JAR 文件(JAR files)类似于EXE文件,只是它们需要Java框架才能运行。将它们想象为Windows上的(Windows)EXE文件,您可以双击它来启动程序。当您运行EXE文件时,它使用Windows 操作系统(Windows OS)支持。同样,在运行JAR文件时,需要借助Java Framework才能打开。当我们说打开JAR文件时,我们并不是像归档文件那样打开文件,而是在执行它。在这篇文章中,我将分享如何在Windows 11/10JAR文件。
什么是 Java 可执行 JAR 文件?
JAR文件是一种归档格式,它不仅存储目录和源文件,还可以作为可执行文件运行。此类Java ARchive文件可以包含将在执行JAR时运行的(JAR)Java类文件。
虽然像7-Zip这样的(7-Zip)存档工具可以从(Archiver tools)JAR文件中提取内容,但这样做是没有意义的——我们需要像运行EXE文件一样执行文件。
如何在Windows 11/10JAR文件
由于Java文件不能单独在 Windows 上运行,因此您需要安装Java 框架(Java Framework)或通常称为Java的东西。也就是说,Java文件可以依赖于特定版本的Java。因此,在 Windows 11/10 上打开JAR(JAR)文件需要采取的步骤是:
- 下载并安装 Java。
- 设置系统路径
- 运行 JAVA 文件
- 设置 Java 文件关联
- 与Java(Java)运行时建立文件关联。
1]下载(Download)并安装Java框架(Java Framework)
要在Windows(Windows)上运行JAR文件,您需要在系统上安装Java。转到Java 下载页面(Java Download Page)并安装它。默认只安装最新版本。但是,如果您的JAR文件需要不同版本的Java,您可以从这里(from here)下载。
有时,现有的旧版Java可能会导致问题。因此,如果您遇到此类问题,请务必先删除旧版本。使用官方的 Java Remover 工具(official Java Remover tool)来摆脱它。然后安装最新版本。
2]为Java设置系统路径
接下来,您需要设置 JAVA_HOME 路径(set the JAVA_HOME path)。它确保您运行的任何JAVA文件都可以找到程序所需的库。您还可以使用命令行回显Java路径以确定它是否正确。
3]运行Java或JAR文件
现在,当您双击JAR文件时,它将像 EXE 文件一样自动运行。如果版本有问题,该文件应通知您。
如果您有一个没有自己运行的JAR文件,那么您可以使用 java JDK来运行它。打开命令提示符(Command Prompt),然后键入 java -jar name_of_jar_file.jar。(type java -jar name_of_jar_file.jar.)它将自动执行JAR文件。
4]设置(Set)Java或JAR文件关联
最后一步是与Java运行时建立文件关联。它将确保每次运行时都不会要求您选择可以执行它的程序。
- Shift + Right-click文件,然后选择打开(Open)方式选项。
- 选择“选择另一个应用程序”。
- 如果Java (TM) Platform SE二进制文件不在您的列表中,请滚动,然后单击更多应用程序(Apps)。
- 然后从计算机中选择选择应用程序。(Select)
- 您应该会在此上下文菜单中看到“ Java (TM) Platform SE binary”,但不要选择它。
- 在我们上面建议的路径中找到可以运行JAVA或JAR文件的文件。(JAR)
- 确保(Make)选中“始终使用此程序”复选框。
完成后,所有未来的JAR文件都将使用(JAR)Java运行时库自动打开。您应该看到所有这些文件的Java图标。
如何从命令行运行 Java JAR?
您需要使用 java 命令来运行 .jar 文件
java -jar <finename>.jar
如果你没有安装java,你可以通过安装default-jre
包来解决这个问题。
We hope these tips were easy to understand and were of help to open or run a Java file on Windows 11/10.
How to open or run a JAR file on Windows 11/10
JAR files are like EXE files except that they need a Java framework to run. Imagine them as EXE files on Windows which you can double click to launch the program. When you run an EXE file, it uses Windows OS support. Similarly, when you run JAR files, you need the help of Java Framework to open. When we say open JAR file, we are not opening the file like an archive file, but we are executing it. In this post, I will share how to open or run a JAR file on Windows 11/10.
What is Java executable JAR file?
A JAR file is an archiving format that not only stores directories and source files and can also be run as executable files. Such Java ARchive files can contain Java class files that will run when the JAR is executed.
While Archiver tools like 7-Zip can extract content from JAR files, but doing that is pointless – we need to execute the files just as we run the EXE files.
How to run a JAR file in Windows 11/10
Since Java files can’t run on Windows on their own, you need to install the Java Framework or what is popularly called Java. That said, Java files can be dependent on a particular version of Java. So the steps you need to take to open JAR files on Windows 11/10 are:
- Download and install Java.
- Set the System path
- Run the JAVA file
- Set Java file association
- Establish a file association with Java runtime.
1] Download and install Java Framework
To run a JAR file on Windows, you need to install Java on your system. Go to Java Download Page, and install it. The default will install the latest version only. However, if your JAR file needs a different version of Java, you can download it from here.
Sometimes, an existing older version of Java can cause an issue. So, if you are facing such a problem, make sure to remove the older version first. Use the official Java Remover tool to get rid of it. Then install the latest version.
2] Set System Path for Java
Next, you need to set the JAVA_HOME path. It makes sure that any JAVA file you run can find the necessary libraries for the program. You can also use the command line to echo the Java path to figure out if it is correct.
3] Run a Java or JAR file
Now when you double click on the JAR file, it will automatically run like how EXE files execute. If there is a problem with version, the file should inform you.
If you have a JAR file which is not running on its own, then you can use java JDK to run it. Open Command Prompt, and type java -jar name_of_jar_file.jar. It will execute the JAR file automatically.
4] Set the Java or JAR file association
The last step is to establish a file association with Java runtime. It will make sure that every time you run, you are not asked to select a program that can execute it.
- Shift + Right-click on the file, and select Open with option.
- Select ‘Choose another app.’
- If Java(TM) Platform SE binary is not in your list, scroll, and then click on More Apps.
- And then choose Select app from the computer.
- You should see ‘Java(TM) Platform SE binary’ listed in this context menu but don’t select it.
- Locate the file which can run the JAVA or JAR file which is available in the path we suggested above.
- Make sure to check the box which says, “Always use this program.”
Once done, all future JAR files will automatically open with Java run time library. You should see the Java icon for all of these files.
How run Java JAR from command line?
You’ll need to use the java command to run a .jar file
java -jar <finename>.jar
If you don’t have java installed, you can fix that by installing the default-jre
package.
We hope these tips were easy to understand and were of help to open or run a Java file on Windows 11/10.