Home  >  Article  >  How to run a JAR file on Windows 11 or 10

How to run a JAR file on Windows 11 or 10

王林
王林forward
2023-05-12 18:34:067025browse

Windows 11 is capable of running a large number of file types, with or without external third-party applications. Not only does it allow you to perform numerous tasks from the comfort of your PC, but it also ensures that you can take advantage of the original capabilities of your PC.

Today we’ll take a look at a complex file type — jar — and tell you how to open it on a Windows 11 or Windows 10 PC.

What is a jar file?

jar is an archive package format that may or may not contain an executable Java program. These archives can contain java applications or source code, which can then be used to compile and run applications without having to write separate code for each application. You can run .jar files on Windows 11 in various ways, and we've listed the most common ones below. Please follow the relevant sections to help you through the process.

How to check if Java is installed

Before we continue, you need to check if Java is installed on your Windows 11 PC. If you don’t use the Java programming language or any similar language, chances are that your Windows 11 PC still doesn’t use Java.

To check whether you have Java installed or not, run the simple command given below. Here's how to do it.

Open the command prompt. Press the Windows key on your keyboard and type cmd. Then click Command Prompt.

如何在 Windows 11 或 10 上运行 JAR 文件

In the command window, type the following command:

java -version

Your screen will look like this:

如何在 Windows 11 或 10 上运行 JAR 文件

Now, press Enter to run it.

Now, if you don't have Java on your machine, you will get an error message stating that the command is not recognized.

如何在 Windows 11 或 10 上运行 JAR 文件

How to install Java (if you don’t have it)

If you don’t have Java on your PC and want to download it to run Java applications, you will need Install the Java Runtime Environment or JRE.

To download the latest version of JRE, please visit the Java download website.

Now, download the executable file for Windows.

如何在 Windows 11 或 10 上运行 JAR 文件

After downloading and installing, go to the command prompt and type “java -version” again as shown above.

如何在 Windows 11 或 10 上运行 JAR 文件

You should now see the version of Java installed on your system.

4 Ways to Run Jar Files on Windows

Running a jar file can be very simple or very difficult. Of course, we'll start with the basics.

Method #01: Double-click to run

After installing the JRE or JDK, you will be able to run the jar file locally on your PC. You should immediately see your jar file as a Java executable. If you don't, you'll need to right-click the jar file and select Run it with OpenJDK Platform Libraries or similar.

如何在 Windows 11 或 10 上运行 JAR 文件

#With any luck, a simple double click will run the jar file like a charm.

Method #02: Create a .bat file to run unsigned or custom .jar archives

If you compiled the .jar archive yourself and want to run the same file on other PCs , then the .bat file can help you. To do this, first, open any Windows Explorer window, click on the three-dot menu icon and select Options.

如何在 Windows 11 或 10 上运行 JAR 文件

Now, go to the View tab and uncheck the Hide extensions for known file types option.

如何在 Windows 11 或 10 上运行 JAR 文件

This will display the full name of the file (with extension).

如何在 Windows 11 或 10 上运行 JAR 文件

#Now, open a notepad file in the folder where the relevant jar file is located. Now add this line to the text file.

java -jar yourfilename.jar

如何在 Windows 11 或 10 上运行 JAR 文件

Now, save the file with the “.bat” extension. You can do the same thing by pressing Ctrl Shift S on your keyboard.

如何在 Windows 11 或 10 上运行 JAR 文件

Just. Now, every time you double-click the batch file, it will be redirected to the jar and the executable should run as scheduled.

Method #03: Repair jar file association

After you create the executable batch file and link it with the Jar, you should be able to run the program smoothly. However, if for some reason you don't get the results you want, we recommend that you check Java file associations.

Packaging/unpacking applications (e.g. WinZip, WinRAR, etc.) may corrupt file associations with JavaAW - the program that ultimately executes the jar file. Follow the tutorial below to help fix .jar file association on your PC.

3.1) Using Settings

Press the Windows ikeyboard to open the Settings app. Now click on "Applications" on the left.

如何在 Windows 11 或 10 上运行 JAR 文件

Now click on “Default Apps”.

如何在 Windows 11 或 10 上运行 JAR 文件

Scroll to the bottom and click "Change defaults by file type."

如何在 Windows 11 或 10 上运行 JAR 文件

Click the search box at the top.

如何在 Windows 11 或 10 上运行 JAR 文件

Now type “jar” and press Enter on your keyboard.

如何在 Windows 11 或 10 上运行 JAR 文件

Click the .jar listing in the search results.

如何在 Windows 11 或 10 上运行 JAR 文件

Click on "More Applications" and select the Java we installed earlier.

如何在 Windows 11 或 10 上运行 JAR 文件

Click "OK" when finished.

如何在 Windows 11 或 10 上运行 JAR 文件

File type association will now be changed for the .jar extension. You should now be able to run the .jar file on your PC with a simple double-click.

3.2) Using .jar file properties

Select the .jar file you are trying to open and hit the Alt Enterkeyboard.

如何在 Windows 11 或 10 上运行 JAR 文件

Click "Change" next to "Open with:".

如何在 Windows 11 或 10 上运行 JAR 文件

Click "More Apps" and then click "Java".

如何在 Windows 11 或 10 上运行 JAR 文件

Click "OK" when finished.

如何在 Windows 11 或 10 上运行 JAR 文件

#Click OK again in the properties window to apply and save your changes.

如何在 Windows 11 或 10 上运行 JAR 文件

That's it! The .jar file type will now be associated with Java and you should be able to open it on your device with a simple double-click.

Method #04: Run .jar files using CMD

You can also easily run .jar files from CMD. Please follow any of the methods below to help you through the process.

Open the folder where the .jar file is located and click on the address bar at the top.

如何在 Windows 11 或 10 上运行 JAR 文件

Type "CMD" and press the Enter key on your keyboard.

如何在 Windows 11 或 10 上运行 JAR 文件

The command prompt will now launch in the same location. Enter the following command and replace "NAME" with the exact name of the .jar file in the same directory.

java -jar NAME.jar

如何在 Windows 11 或 10 上运行 JAR 文件

That’s it! You will now execute the required .jar files from the command prompt.

FAQ

.Jar file archives are sometimes misunderstood as executable files and vice versa. Opening and running both on Windows requires different approaches, so here are some FAQs to help you get started quickly.

Can I run .jar games using these methods?

No, unfortunately you will need a third-party .jar game loader to help you launch and configure your game accordingly. The game also needs to save your progress, which is also handled by such third-party applications.

Why can't I extract the .jar archive?

We recommend that you verify the .jar file and make sure it is an archive file. In most cases, unsupported content is the reason why you cannot extract .jar files on your system. Additionally, the developer needs to define the file as an archive so that it is recognized as the same on your device.

What is the best way to run a .jar file?

We recommend that you stick to the double-click method. If your file type associations are messed up, you can use the tutorial above to fix it on your device. However, if in the rare case that the double-click method doesn't work for you, we recommend you to try the command line method.

The above is the detailed content of How to run a JAR file on Windows 11 or 10. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yundongfang.com. If there is any infringement, please contact admin@php.cn delete