- How to run a JAR file on Windows 10 [QUICK GUIDE]
- How can I run a JAR file on Windows 10?
- 1. Add Java to Windows
- 2. Download a JAR file opener
- File Viewer Plus
- 3. Use Java(TM) Platform SE binary
- 4. Run a JAR file from the Windows Command Prompt
- 5. Add a third-party JAR executor to Windows
- How to run a JAR file
- 11 Answers 11
- Running JAR file on Windows
- 25 Answers 25
- Run a .jar file on Windows 7
- 3 Answers 3
- Запуск файла JAR в Windows
How to run a JAR file on Windows 10 [QUICK GUIDE]
- To run a JAR file on your Windows 10 device you certainly need to have Jave installed.
- You’ll find below a path to the latest Java version in case you need it.
- Then, you can find JAR file openers or executors, and we recommend some.
- Using Command Prompt is also a handy solution if you don’t want to install third-party tools.
A JAR file is a Java archive package format that might include a Java program within it. While you can extract JARs with archive software such as 7zip, you can’t run a pure Java JAR app as you would with other programs in Windows.
Since that’s the case, we’ll cover how you can run a pure Java app JAR file in Windows.
How can I run a JAR file on Windows 10?
1. Add Java to Windows
The crucial thing you need upfront is to have Java installed. Without it, Java apps aren’t going to run in Windows. This is how you can install or update Java in Windows 10:
- First, open Command Prompt(Admin) by pressing the Win key + R keyboard combination and entering cmd in the box.
- Next, input java -version in the Command Prompt and press Enter. It will then provide further details on your Java version as below.
- The current version of Java is Version 8 Update 131. If you don’t have Java or the most up-to-date version, you can add it for free.
- Run through the Java setup wizard. Then, open your browser to verify that the program is working.
2. Download a JAR file opener
You can open JAR files and hundreds of different formats with a single application. File Viewer Plus is a universal file viewer for Windows that can open and display over 300 different file types.
The new updated version has a plethora of features that will save you big time on opening, viewing, or editing files.
File Viewer Plus supports the most popular text, audio or video file type, as well as archive, source code or web files.
File Viewer Plus
3. Use Java(TM) Platform SE binary
- Open the File Explorer and the folder that includes the file you need to run.
- You should right-click the JAR file and select Open with from the context menu.
- Click Choose another app and then select to open it with Java(TM) Platform SE binary.
- Click the Always use this app to open JAR files check box.
- Press the OK button to close the menu.
- Now you can run the selected JAR, and all other JARfiles will also be associated with Java.
4. Run a JAR file from the Windows Command Prompt
- Press the Win key + X hotkey and select Command Prompt (Admin) to open it as administrator.
- Then input the following command (replacing the example with the actual path of the file you need to run) and press Enter: java -jar c:pathtojarfile.jar
- Alternatively, you can open the folder that includes the JAR in the Command Prompt first by entering cd / followed by the directory. Then, you can input java -jar file.jar without the folder path.
That will open the executable JAR file so long as it contains a manifest file to specify the application’s entry point. (The developers should have already included that in the archive.)
If you develop your own Java programs, you’ll need to convert the JAR to an executable format.
5. Add a third-party JAR executor to Windows
There are also executor programs for Windows that enable you to run JAR files the same as any other program . Jarx is one of them and you can add it to Windows by clicking Jarx-1.2-installer.exe on this page.
Click the jarx .exe to run the software, which doesn’t really have a GUI as such (except an About jarx window). Then you can double-click the JAR files to run them in Windows.
If you’re having trouble accessing the JAR file or you get some kind of an error, take a look at this nifty guide to finding some great fixes.
With all this, you can now run JAR files in Windows. If you need to fix a JAR file that isn’t opening, check out this Windows Report guide.
If you have any other suggestions or questions, leave them in the comments section below and we’ll be sure to take a look.
How to run a JAR file
I created a JAR file like this:
I ran this JAR file by double clicking on it (it didn’t work). So I ran it from the DOS prompt like this:
It raised «Failed to load main class» exceptions. So I extracted this JAR file:
and I ran the class file:
It worked well. I do not know why the JAR file did not work. Please tell me the steps to run the JAR file
11 Answers 11
You need to specify a Main-Class in the jar file manifest.
Oracle’s tutorial contains a complete demonstration, but here’s another one from scratch. You need two files:
Note that the text file must end with a new line or carriage return. The last line will not be parsed properly if it does not end with a new line or carriage return.
Before run the jar check Main-Class: classname is available or not in MANIFEST.MF file. MANIFEST.MF is present in jar.
You have to add a manifest to the jar, which tells the java runtime what the main class is. Create a file ‘Manifest.mf’ with the following content:
Change ‘your.programs.MainClass’ to your actual main class. Now put the file into the Jar-file, in a subfolder named ‘META-INF’. You can use any ZIP-utility for that.
A very simple approach to create .class, .jar file.
Executing the jar file. No need to worry too much about manifest file. Make it simple and elgant.
Java sample Hello World Program
Compiling the class file
Creating the jar file
Running the jar file
If you don`t want to create a manifest just to run the jar file, you can reference the main-class directly from the command line when you run the jar file.
This sets the which main-class to run in the jar file.
On command Line:
If you don’t want to deal with those details, you can also use the export jar assistants from Eclipse or NetBeans.
Eclipse Runnable JAR File
Create a Java Project – RunnableJAR
- If any jar files are used then add them to project build path.
- Select the class having main() while creating Runnable Jar file.
Run Jar file using java program (cmd) by supplying arguments and get the output and display in eclipse console.
Help ► Help Contents ► Java development user guide ► References ► Menus and Actions
I have this folder structure:
D:\JavaProjects\OlivePressApp\com\lynda\olivepress\Main.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\press\OlivePress.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Kalamata.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Ligurian.class D:\JavaProjects\OlivePressApp\com\lynda\olivepress\olives\Olive.class
Main.class is in package com.lynda.olivepress
There are two other packages:
1) Create a file named «Manifest.txt» with Two Lines, First with Main-Class and a Second Empty Line.
2) Create JAR with Manifest and Main-Class Entry Point
D:\JavaProjects\OlivePressApp> jar cfm OlivePressApp.jar Manifest.txt com/lynda/olivepress/Main.class com/lynda/olivepress/*
java -jar OlivePressApp.jar
Note: com/lynda/olivepress/* means including the other two packages mentioned above, before point 1)
Running JAR file on Windows
I have a JAR file named helloworld.jar. In order to run it, I’m executing the following command in a command-line window:
This works fine, but how do I execute it with double-click instead? Do I need to install any software?
25 Answers 25
Easiest route is probably upgrading or re-installing the Java Runtime Environment (JRE).
- Open the Windows Explorer, from the Tools select ‘Folder Options. ‘
- Click the File Types tab, scroll down and select JAR File type.
- Press the Advanced button.
- In the Edit File Type dialog box, select open in Actions box and click Edit.
- Press the Browse button and navigate to the location the Java interpreter javaw.exe.
- In the Application used to perform action field, needs to display something similar to C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe» -jar «%1» % (Note: the part starting with ‘javaw’ must be exactly like that; the other part of the path name can vary depending on which version of Java you’re using) then press the OK buttons until all the dialogs are closed.
In Windows Vista or Windows 7, the manual file association editor has been removed.
The easiest way is to run Jarfix, a tiny but powerful freeware tool. Just run it and your Java apps is back. double-clickable again.
If you need to distribute your .jar file and make it runnable at other people’s Windows computers, you can make a simple .bat file like this in the command prompt:
and place the .bat file in the same directory as your .jar file.
If you have a jar file called Example.jar, follow these rules:
- Open a notepad.exe
- Write : java -jar Example.jar
- Save it with the extension .bat
- Copy it to the directory which has the .jar file
- Double click it to run your .jar file
An interesting side effect of this causes a problem when starting runnable jar files in the command prompt.
If you try (in a command prompt):
No joy, because this is being translated to the following (which doesn’t work):
However, the following command does work:
If you change the association in file manager as described above to:
Then you can type:
in the command prompt and it will now work!
EDIT:(However you then get a black console window when you run a form based (non console) Java app, so this is not an ideal solution)
If you run these jar files by double clicking them in windows, no parameters will be passed so your Java code needs to handle the stack overflow exception and include a «press a key» function at the end or the window will just disappear.
In order to pass a parameter in windows you have to create a shortcut to the jar file, which includes the parameter in the target line (right click on the shortcut and select properties) you can not add parameters to the jar file icon itself in this way.
There isn’t a single, consistent solution here, but you would have the same problem with any other console application.
There is a windows freeware application called «bat to exe» which you can use to create an exe file from a .bat file with the apropriate command line in it. you can also embed the jar file in the exe with this application, and make it clean it up when it has finished running, so this may be a more elegant solution.
Run a .jar file on Windows 7
I have downloaded a .jar file and it won’t run on my computer. I have installed Java RE 5.0 and have Java 7 update 72. Every time I double click on the file it pops up and closes.
I have reinstalled the java re and java 7u72 and still no success.
Any help with running executable .jar file on windows 7?
3 Answers 3
By default, java does not run in windows mode, maybe it’s just a console java program.
The .jar file must have a lib folder in the folder the .jar is in to open a window (without using native java libraries). If it doesn’t, then the .jar won’t open any windows, as it needs external libraries to do so. However, if your .jar isn’t meant to open any windows, then it has been performing as expected. Try running your .jar from the command line:
Have you checked the Environment Variables? Maybe the variable PATH is not specified. Besides, you can try this:
If it doesn’t work, try to configure the Environment Variables:
Note: You may see a PATH environment variable similar to the following when editing it from the Control Panel:
Variables enclosed in percentage signs (%) are existing environment variables. If one of these variables is listed in the Environment Variables window from the Control Panel (such as JAVA_HOME), then you can edit its value. If it does not appear, then it is a special environment variable that the operating system has defined. For example, SystemRoot is the location of the Microsoft Windows system folder. To obtain the value of a environment variable, enter the following at a command prompt. (This example obtains the value of the SystemRoot environment variable):
Запуск файла JAR в Windows
У меня есть файл JAR с именем helloworld.jar . Чтобы запустить его, я выполняю следующую команду в окне командной строки:
Это работает нормально, но как мне выполнить его двойным щелчком вместо этого? Нужно ли устанавливать какое-либо программное обеспечение?
Самый простой путь — это обновление или переустановка Java Runtime Environment (JRE).
- Откройте проводник Windows, в меню «Инструменты» выберите «Параметры папки . »
- Перейдите на вкладку «Типы файлов», прокрутите вниз и выберите «Тип файла JAR».
- Нажмите кнопку Дополнительно.
- В диалоговом окне «Редактировать тип файла» выберите «Открыть» в поле «Действия» и нажмите «Изменить».
- Нажмите кнопку Обзор и перейдите к местоположению интерпретатора Java javaw.exe.
- В Приложении, используемом для выполнения поля действия, должно отображаться что-то похожее на C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe» -jar «%1» % (Примечание: часть, начинающаяся с ‘javaw’, должна быть точно такой же; другая часть имени пути может отличаться в зависимости от используемой версии Java ) затем нажимайте кнопки ОК, пока все диалоговые окна не будут закрыты.
В Windows Vista или Windows 7 ручной редактор сопоставления файлов был удален.
Самый простой способ — запустить Jarfix , крошечный, но мощный бесплатный инструмент. Просто запустите его, и ваши Java-приложения вернутся . снова дважды щелкните мышью.
Если вам нужно распространить файл .jar и сделать его работоспособным на компьютерах Windows других людей, вы можете создать простой файл .bat, например, в командной строке:
и поместите файл .bat в тот же каталог, что и ваш файл .jar.
Если у вас есть файл jar с именем Example.jar, следуйте этим правилам:
- Открыть notepad.exe
- Напишите : java -jar Example.jar
- Сохраните это с расширением .bat
- Скопируйте его в каталог, в котором находится .jar файл
- Дважды щелкните по нему, чтобы запустить .jar файл
Интересный побочный эффект этого вызывает проблему при запуске запускаемых файлов JAR в командной строке.
Если вы попробуете (в командной строке):
Нет радости, потому что это переводится на следующее (что не работает):
Тем не менее, следующая команда работает:
Если вы измените связь в файловом менеджере, как описано выше:
Затем вы можете ввести:
в командной строке и теперь он будет работать!
РЕДАКТИРОВАТЬ: (Однако вы получите черное окно консоли при запуске Java-приложения на основе формы (не консоль), так что это не идеальное решение)
Если вы запустите эти jar-файлы, дважды щелкнув их в окнах, параметры не будут переданы, поэтому ваш Java-код должен обрабатывать исключение переполнения стека и включать в конце функцию «нажать клавишу», иначе окно просто исчезнет.
Чтобы передать параметр в windows, вы должны создать ярлык для файла JAR, который включает в себя параметр в целевой строке (щелкните правой кнопкой мыши по ярлыку и выберите свойства), вы не можете добавлять параметры к самому значку файла JAR в этом путь.
Здесь нет единого согласованного решения, но у вас будет такая же проблема с любым другим консольным приложением.
Существует бесплатное приложение для Windows под названием «bat to exe», которое можно использовать для создания exe-файла из .bat-файла с соответствующей командной строкой в нем. Вы также можете вставить jar-файл в исполняемый файл с этим приложением и заставить его очистить его после завершения работы, так что это может быть более элегантным решением.