jar 文件是 Java AR chive 文件的缩写,其中包含Java(AR)程序(J)(Java类文件、元数据和资源)。作为一种包文件格式(类似于 .zip 文件格式),jar 文件也可用于将其他几个文件打包在一起,以提高可移植性并减少这些文件占用的空间量。这使得 jar 文件非常通用,可用于存储游戏、应用程序、浏览器扩展等。
并非所有的 jar 文件都是一样的。有些旨在像.exe文件一样运行/执行,而另一些extracted/unpacked like .zip files。虽然解压 jar 文件非常容易,并且可以像提取 zip 文件的内容一样完成,但执行 jar 文件的情况并非如此。
双击时的 .exe 文件在Windows 操作系统(Windows OS)的帮助下启动程序/应用程序。类似地,可以通过使用Java 框架(Java Framework)启动 .jar 文件来执行它。但是,许多用户在尝试执行 jar 文件时会遇到错误,今天,在本文中,我们将对此进行一些说明,并揭示如何在Windows 10上运行或执行 jar 文件。
为什么jar文件不会运行?(Why won’t jar files run? )
一个Jar文件包含一个清单,该清单主要告诉文件如何表现,同时保存有关打包在 jar 文件中的其他文件的信息。此外,jar 文件包含保存可执行程序的 java 代码的类文件。这两个文件以及其他媒体文件都可以通过Java Runtime Environment(Java Runtime Environment)将 jar 文件作为单个请求运行。
用户在尝试运行 jar 文件时会遇到这两个错误之一。
- Java 运行时环境(Java Run-Time Environment)未正确设置为运行 .jar 文件
- Windows 注册表未正确调用JRE(Java 运行时环境)(JRE (Java Runtime Environment))
当用户在他或她的个人计算机上运行过时版本的 java 时会出现第一个错误,而当 jar 文件与Java二进制文件没有正确关联时会导致第二个错误。
此外,有时当用户双击 jar 文件时,命令提示符窗口会在瞬间启动,然后关闭,让用户感到沮丧。幸运的是,解决这两个错误并运行 jar 文件非常容易。
如何在 Windows 10 上运行 JAR 文件
如前所述,您需要Java 运行时环境(Java Runtime Environment)来运行 jar 文件中包含的应用程序/代码。要检查您的个人计算机运行的Java版本以及如何更新到最新版本,请按照以下步骤操作:
1.通过以下任何一种方法以管理员(Administrator)身份启动命令提示符。(Command Prompt)
一种。按Windows键 + X 或右键单击开始按钮以打开高级用户菜单。从随后的菜单中,单击命令提示符(Command Prompt)( Admin )。
湾。按 Windows(Press Windows)键 + R 启动运行(Run)命令,键入 cmd 并按 ctrl + shift + enter。
C。单击(Click)开始按钮(或按Windows键 + S),键入命令提示符并从右侧面板中选择以管理员身份(Administrator)运行。(Run)
2. 打开命令提示符窗口后,键入java -version并按 Enter。
命令提示符现在将为您提供您在系统上安装的Java的确切版本。(Java)
或者,在您的 PC 上搜索配置 java(configure java)应用程序,然后单击常规选项卡中的关于(About )以检索 java 版本。
3. Java(Java)的最新版本是Version 8 Update 251(截至2020 年 4 月 14 日(April 2020))。如果您没有使用最新版本或根本没有Java,请前往官方下载页面Java 下载适用于所有操作系统(Java Downloads for All Operating Systems),然后单击“同意并开始免费下载”(Agree and Start Free Download” )按钮。
4. 找到下载的文件(此 PC > Downloads)并双击.exe文件以打开安装向导。现在,按照屏幕上的提示安装最新版本的Java。
5.重复(Reiterate)步骤 1 和 2 以检查更新是否成功安装。
如果您在更新 java 时遇到任何问题,请先尝试使用官方 Java 删除工具(official Java Removal Tool)完全删除以前的版本,然后执行全新安装。
方法 1:使用“打开方式...”
在第一种方法中,我们使用Java Runtime Environment手动打开 jar 文件。请按照以下步骤执行相同操作。
1. 打开文件资源管理器(Windows key + E),找到您要执行/打开的 jar 文件并右键单击它。
2. 从以下文件选项/上下文菜单中,选择打开方式。(Open with.)
3. 浏览应用程序列表并尝试找到Java(TM) Platform SE 二进制文件(Java(TM) Platform SE binary)。您很可能在应用程序列表中找不到它。
4. 所以,点击选择另一个应用程序(Choose another app)。
5. 再次浏览列表,如果未找到应用程序,请单击更多应用程序 >在此 PC 上(on this PC)More Apps > Look for another app 以手动查找应用程序
6. 现在,导航到 java.exe 的存储路径。对于大多数用户来说,它应该是C:\Program Files\Java\jre1.8.0_221\bin但如果你在那里找不到它,请尝试沿着以下路径 C:Program Files (x86)Javajre1.8.0_221 in
7. 最后,选择java.exe并回车。
方法 2:使用命令提示符(Command Prompt)运行 JAR(Run JAR)文件
还可以使用Windows 10命令提示符窗口运行 jar 文件。该过程涉及执行单个命令行并且易于执行。
1.使用前面提到的任何方法以管理员身份启动命令提示符。(Launch Command Prompt as Administrator)
2. 启动命令提示符窗口后,运行命令‘cd \’ 返回目录顶部。
3. 现在,输入以下命令java -jar sample.jar并按回车键。
不要忘记在命令行中将“sample .jar ”更改为(.jar).jar文件的名称。
或者,您可以跳过第二步,将 sample.jar 替换为 jar 文件的完整路径。
另请阅读:(Also Read:) 修复 Java 已启动但返回退出代码 1(Fix Java was started but returned exit code 1)
方法 3:使用第三方应用程序
就像其他一切一样,存在多个第三方应用程序可让您在Windows 10上运行或执行 jar 文件。互联网上比较流行的 jar 执行程序之一是Jarx。
前往官方网站Jarx – JAR 执行(Jarx – The JAR executer)器并通过单击“ Jarx -1.2-installer.exe”下载软件文件。找到下载的文件并安装Jarx。除了关于窗口外,该应用程序没有GUI 。现在,只需双击 jar 文件或右键单击并选择打开即可在您的个人计算机上运行 jar 文件。
另一个可以帮助您运行 jar 文件的第三方应用程序是Jarfix。按照为Jarx讨论的相同过程运行 jar 文件。
注意:(Note:) Jarfix只能在以管理员身份启动时运行 jar 文件。
方法 4:提取 Jar 文件
如前所述,并非所有 jar 文件都设计/旨在成为可执行文件。有些只是作为一个包工作,并在其中保存其他类型的文件。我们可以通过简单地解压/解压来检查 jar 文件是否可执行。
如果您曾经使用过 zip 文件和 rar 文件,那么您很可能已经知道如何提取文件。可以选择使用 Windows 中的内置提取工具,或者从 Internet 上可用的众多文件提取应用程序之一中获取帮助。一些最常用和最受信任的应用程序是7-zip 和 WinRAR(7-zip and WinRAR)。
要使用 Windows 的内置提取工具提取文件,只需右键单击(right-click)jar 文件并选择“提取...”(‘Extract…’)选项之一。
要使用第三方应用程序提取文件,首先,前往应用程序的网站并下载安装文件。完成应用程序安装后,打开应用程序中的 jar 文件以查看其中包含的内容。
修复无法(Fix Unable)在Windows 10上打开JAR 文件(JAR Files)
如果您无法使用上述任何方法运行 jar 文件,请尝试通过以下解决方案。
解决方案 1:更新注册表编辑器(Registry Editor)
1. 启动文件资源管理器(Windows Key + E)并导航到 java 安装文件夹内的 bin 文件夹。
文件夹目标取决于您安装它的驱动器分区。但是,对于大多数用户来说,该文件夹可以在 C 盘和Program Files或Program Files ( x86 ) 中找到。
2. 在 bin 文件夹中,找到 java.exe,右键单击它并选择Properties。
3. 切换到兼容性选项卡并勾选(Compatibility )以管理员(Run this program as an Administrator)身份运行此程序旁边的框。单击(Click)应用(Apply),然后单击确定退出。
4.通过前面提到的任何方法以管理员身份启动命令提示符。(Launch Command Prompt as administrator)
5. 根据您的要求,在命令提示符窗口中键入以下命令之一,然后按 Enter。
不要忘记将 C:Program Files(x86) 替换为您的实际Java安装文件夹地址。
要简单地启动 jar 文件,请键入以下命令并按 Enter:
ftype jarfileterm=cmd /s /k “”C:\Program Files(x86)\Java\jre1.8.0_221\bin\java.exe” -jar “%1″ %*”
assoc .jar=jarfileterm
6. 如果您想调试 jar 文件并因此需要在启动文件后命令提示符窗口保持打开状态,请键入以下命令
ftype jarfileterm=cmd /s /k “”C:\Program Files(x86)\Java\jre1.8.0_221\bin\java.exe” -jar “%1″ %*”
assoc .jar=jarfileterm
现在继续尝试打开 jar 文件。
如果您仍然无法执行 jar 文件,我们将需要在Windows 注册表编辑器(Windows Registry Editor)中进行一些更改。我们建议您在遵循以下指南时要格外小心,因为注册表编辑器(Registry Editor)是一个强大的工具,不应被弄乱。
1.通过单击开始按钮、搜索注册表编辑器并按 Enter 或在运行命令(Windows Key + R)中键入 regedit 来启动(Launch the )Windows 注册表编辑器。(Windows Registry Editor)
2. 在左侧面板中,单击箭头或双击HKEY_CLASSES_ROOT以展开相同的内容。
3. 从下拉列表中找到jarfile文件夹(有些用户可能会找到文件夹jar_auto_file和jarfileterm而不是 jarfile。按照下面提到的相同步骤进行操作)
4.首先(First)双击打开jarfile。
5. 导航到 jarfile > shell > open > command
5. 在右侧面板上,您应该会看到一个标有Default的键。右键单击(Right-click)并选择修改(Modify )或简单地双击它来修改密钥。
6. 在下面的弹出框中,在数值数据(Value Data)标签下,粘贴我们之前在命令提示符窗口中输入的fftype命令。(fftype)
7. 交叉检查以确保正确,然后按OK。
注意:(Note:) 记住(Remember)要遵循两个文件夹jar_auto_file 和 jarfileterm 的完整过程,(jar_auto_file & jarfileterm,)如果有的话)
8. 最后,关闭注册表编辑器并尝试启动 jar 文件。
解决方案 2:更改Java 安全设置(Java Security Settings)
Java的另一个非常常见的问题是安全风险。尝试运行 jar 文件时,经常会弹出声称有风险的警告消息。为了解决这个问题,我们只需要更改安全设置。
1.点击开始按钮或按Windows Key + S,搜索Configure Java并回车打开。
2.通过单击切换到安全选项卡。(Security )
3. 确保选中“为浏览器和 Web Start 应用程序启用 Java 内容”旁边的框。( ‘Enable Java content for browser and Web Start applications’ is ticked.)
4. 将不在例外站点(Exception Site)列表中的应用程序的安全级别设置为高(High ),然后单击应用(Apply)。
5. 单击确定(OK )退出。
受到推崇的:(Recommended:)
我们希望您能够按预期在Windows 10上运行或执行您的 jar 文件。(Windows 10)如果按照上述指南或打开 jar 文件时遇到任何问题,请在下面的评论部分与我们联系,我们将为您提供帮助。
How to Run JAR Files on Windows 10
A jar file is short for a Java ARchive file and holds java programs (Java class files, metadata, and resources) within it. Being a package file format (similar to .zip file format ), a jar file may also be used to pack together several other files to improve portability and decrease the amount of space that these files take up. This makes jar files extremely versatile and can be used to store a game, an application, a browser extension, etc.
Not all jar files are created equal. Some are meant to be run/executed like .exe files and others extracted/unpacked like .zip files. While unpacking jar files is quite easy and can be done similarly to how one would extract the contents of a zip file, the same isn’t the case for executing a jar file.
A .exe file when double-clicked launches a program/application with the help of the Windows OS. Similarly, a .jar file can be executed by launching it using the Java Framework. However, many users face errors when trying to execute jar files and today, in this article, we will shed some light on the matter and reveal how to run or execute jar files on Windows 10.
Why won’t jar files run?
A Jar file includes a manifest that essentially tells the file how to behave while holding information about the other files packed within the jar file. Also, a jar file contains class files that hold the java code for the executable program. Both of these files along with other media files make it possible to run jar files as a single request by Java Runtime Environment.
Users come across one of these two errors when trying to run a jar file.
The first error arises when the user is running an outdated version of java on his or her personal computer and the second one is caused when the jar files are not properly associated with the Java binary.
Also, sometimes when a user double-clicks on a jar file, a command prompt window launches for a split-second and then closes back down leaving the user in dismay. Fortunately, resolving these two errors and running a jar file is quite easy.
How to Run JAR Files on Windows 10
As mentioned earlier, you require the Java Runtime Environment to run the application/code contained inside a jar file. To check what version of Java your personal computer is running and how to update to the latest version, follow the below-mentioned steps:
1. Launch Command Prompt as Administrator by any of the methods mentioned below.
a. Press Windows key + X or right-click on the start button to open the power user menu. From the ensuing menu, click on Command Prompt (Admin).
b. Press Windows key + R to launch Run command, type cmd and press ctrl + shift + enter.
c. Click on the start button (or press the Windows key + S), type command prompt and select Run as Administrator from the right panel.
2. Once the command prompt window is open, type java -version and press enter.
The command prompt will now provide you with the exact version of Java you have installed on your system.
Alternatively, search for the configure java application on your PC and click on About in the general tab to retrieve java version.
3. The latest version of Java is Version 8 Update 251 (as of 14th April 2020). If you aren’t using the latest version or don’t have Java at all, head over to the official download page Java Downloads for All Operating Systems and click on the “Agree and Start Free Download” button.
4. Locate the downloaded file (This PC > Downloads) and double-click on the .exe file to open the setup wizard. Now, follow the on-screen prompts to install the latest version of Java.
5. Reiterate through steps 1 and 2 to check if the update was successfully installed.
If you are facing any issues in updating java, try completely removing the previous version first using the official Java Removal Tool and then performing a fresh install.
Method 1: Using ‘Open With…’
In the first method, we manually open the jar file with the Java Runtime Environment. Follow the below steps to do the same.
1. Open the file explorer (Windows key + E), locate the jar file you would like to execute/open and right-click on it.
2. From the following file options/context menu, select Open with.
3. Go through the list of applications and try to locate Java(TM) Platform SE binary. It is most likely that you won’t find it in the list of applications.
4. So, click on Choose another app.
5. Again, go through the list and if do not find the application click on More Apps > Look for another app on this PC to manually find the application
6. Now, navigate to the path where java.exe is stored. For most users, it should be C:\Program Files\Java\jre1.8.0_221\bin but if you do not find it there, try going down the following path C:\Program Files (x86)\Java\jre1.8.0_221\bin
7. Finally, select java.exe and press enter.
Method 2: Run JAR files using the Command Prompt
One can also run jar files using the Windows 10 command prompt window. The process involves executing a single command line and is easy to perform.
1. Launch Command Prompt as Administrator using any of the methods mentioned earlier.
2. Once the command prompt window has launched, run the command ‘cd \’ to return to the top of the directory.
3. Now, type the following command java -jar sample.jar and hit the enter key.
Do not forget to change ‘sample.jar’ in the command line with the name of the .jar file.
Alternatively, you can skip the second step and replace sample.jar with the complete path of the jar file.
Also Read: Fix Java was started but returned exit code 1
Method 3: Using Third-Party Applications
Just like for everything else, there exist multiple third-party applications that let you run or execute jar files on Windows 10. One of the more popular jar executor programs out there on the internet is Jarx.
Head over to the official site Jarx – The JAR executer and download the software file by clicking on ‘Jarx-1.2-installer.exe’. Locate the downloaded file and install Jarx. The application doesn’t have a GUI except for an about window. Now, simply double-click on the jar file or right-click and select open to run jar files on your personal computer.
Another third-party application that will aid you in running jar files is Jarfix. Follow the same procedure as discussed for Jarx to run jar files.
Note: Jarfix will only be able to run jar files when launched as an administrator.
Method 4: Extract the Jar Files
As mentioned earlier, not all jar files are designed/meant to be an executable file. Some just work as a package and hold other types of files in them. We can check if a jar file is executable or not by simply unpackaging/extracting it.
If you have ever worked with zip files and rar files, chances are, you already know how to extract a file. One can choose to use the builtin extraction tool in windows or take assistance from one of the many files extracting applications available on the internet. Some of the most used and trusted applications are 7-zip and WinRAR.
To extract a file using Windows’ in-built extracting tool, simply right-click on the jar file and select one of the ‘Extract…’ options.
To extract a file using a third-party application, first, head over to the application’s website and download the installation file. Once you are done installing the application, open the jar file in the application to see the content it holds.
Fix Unable to Open JAR Files on Windows 10
If you were not able to run the jar files using any of the above methods, then try going through the following solution.
Solution 1: Updating Registry Editor
1. Launch File Explorer (Windows Key + E) and navigate to the bin folder inside the java installation folder.
The folder destination varies depending on the drive partition you have it installed on. However, for most users, the folder can be found in C drive and inside Program Files or Program Files (x86).
2. Inside the bin folder, find java.exe, right-click on it and select Properties.
3. Switch over to the Compatibility tab and tick the box next to Run this program as an Administrator. Click on Apply followed by Ok to exit.
4. Launch Command Prompt as administrator by any of the methods mentioned earlier.
5. Depending on your requirements type one of the following commands in the command prompt window and press enter.
Do not forget to replace C:\Program Files(x86)\ with your actual Java installation folder address.
To simply launch the jar file, type the following commands and hit Enter:
ftype jarfileterm=cmd /s /k “”C:\Program Files(x86)\Java\jre1.8.0_221\bin\java.exe” -jar “%1″ %*”
assoc .jar=jarfileterm
6. If you would like to debug the jar file and thus need the command prompt window to stay open after launching the file, type the following command
ftype jarfileterm=cmd /s /k “”C:\Program Files(x86)\Java\jre1.8.0_221\bin\java.exe” -jar “%1″ %*”
assoc .jar=jarfileterm
Now go ahead and try opening the jar file.
If you are still not able to execute the jar file, we will need to change a few things in the Windows Registry Editor. We advise you to be extremely cautious in following the below guide as the Registry Editor is a powerful tool and shouldn’t be messed with.
1. Launch the Windows Registry Editor by clicking on the start button, searching for registry editor and pressing enter or by typing regedit in the run command (Windows Key + R).
2. From the left-hand panel, click on the arrow or double click on HKEY_CLASSES_ROOT to expand the same.
3. From the drop-down list, find the folder jarfile (Some users may find the folders jar_auto_file and jarfileterm instead of jarfile. Follow the same procedure as mentioned below)
4. First open jarfile by double-clicking on it.
5. Navigate to jarfile > shell > open > command
5. On the right-hand panel, you should see a key labelled Default. Right-click and select Modify or simply double-click on it to modify the key.
6. In the following pop up box, under the Value Data label, paste the fftype command we entered earlier in the command prompt window.
7. Cross-check to make sure it is correct and press OK.
Note: Remember to follow the complete the procedure for both folders, jar_auto_file & jarfileterm, if you have them)
8. Finally, close the registry editor and try launching the jar file.
Solution 2: Change Java Security Settings
Another very common issue with Java is the security risk. A warning message claiming risk often pops up when trying to run a jar file. To resolve this, we simply need to change the security settings.
1. Click on the start button or press Windows Key + S, search for Configure Java and press enter to open.
2. Switch over to the Security tab by clicking on the same.
3. Make sure the box next to ‘Enable Java content for browser and Web Start applications’ is ticked.
4. Set the security level for applications not on the Exception Site list to High and click on Apply.
5. Click on OK to exit.
Recommended:
We hope you were able to run or execute your jar file on Windows 10 as intended. In case of any issues following the above guide or in opening a jar file, connect with us in the comments section below and we will help you out.