Running java jar on windows

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):

jarfile.jar parameter

No joy, because this is being translated to the following (which doesn’t work):

javaw.exe -jar jarfile.jar parameter

However, the following command does work:

java.exe -jar jarfile.jar parameter

If you change the association in file manager as described above to:

"C:\Program Files\Java\j2re1.4.2_04\bin\java.exe" -jar "%1" %*

Then you can type:

jarfile.jar parameter

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.

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):

jarfile.jar parameter

No joy, because this is being translated to the following (which doesn’t work):

javaw.exe -jar jarfile.jar parameter

However, the following command does work:

java.exe -jar jarfile.jar parameter

If you change the association in file manager as described above to:

"C:\Program Files\Java\j2re1.4.2_04\bin\java.exe" -jar "%1" %*

Then you can type:

jarfile.jar parameter

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.

by Matthew Adams

Matthew is a freelancer who has produced a variety of articles on various topics related to technology. His main focus is the Windows OS and all the things… read more


Updated on

  • 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.

run a Jar file on Windows 10 PC

A JAR file is a Java archive package format that might include a Java program within it.

While you can extract JARs with archiving software, 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.

What are JAR files?

A JAR file allows Java runtimes to enclose an entire application, together with its classes and resources, in a single source.

Moreover, the elements inside a JAR file can be compressed, and that translates to shorter download times but also less space allocated on your drive.

In other words, JARs are more sophisticated archives that work in a Java environment on your PC.

How can I run a JAR file?

In this article

  • What are JAR files?
  • How can I run a JAR file?
  • 1. Add Java to Windows
  • 2. Use Java (TM) Platform SE binary
  • 3. Download a JAR file opener
  • 4. Run a JAR file in cmd
  • 5. Add a third-party JAR executor to Windows
  • How to get a JAR file for your favorite app?

1. Add Java to Windows

  1. Type cmd in the Windows Search tab and click on the Command Prompt app.
  2. Next, input the following command and press Enter to run it: java -version
  3. The current version of Java is Version 8 Update 311.
  4. If you don’t have Java or the most up-to-date version, you can download it for free. After you get the file, hit the Install button.
  5. Run through the Java setup wizard and close the window after the installation process.
  6. Then, open your browser to verify that the program is working.

The crucial thing you need upfront is to have Java installed. It helps you open JAR files. Without it, Java apps aren’t going to run in Windows.

How we test, review and rate?

We have worked for the past 6 months on building a new review system on how we produce content. Using it, we have subsequently redone most of our articles to provide actual hands-on expertise on the guides we made.

For more details you can read how we test, review, and rate at WindowsReport.

2. Use Java (TM) Platform SE binary

  1. Press the Windows key + E to start File Explorer and the folder that includes the file you need to run.
  2. You should right-click the JAR file and select Open with from the context menu, then select Choose another app.
  3. Sselect to open it with Java(TM) Platform SE binary.
  4. Click the Always use this app to open JAR files check box, then press the OK button to close the menu.
  5. Now you can run the selected JAR, and all other JARfiles will also be associated with Java.

3. Download a JAR file opener

  1. Go to the File Viewer Plus website and click on the Download Now button.
  2. After you download and install the app, hit the Finish button.
  3. Now click on the Open a file button or just drag-and-drop the JAR file in its window.
  4. You will instantly see the contents of the JAR file and you will be able to click the Extract All button to get them on a location on your drive.

You can open JAR files with a lot of apps out there but we strongly recommend File Viewer Plus because it 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.

Keep in mind that the app supports the most popular text, audio, or video file type, as well as archive, source code, or web files.

Another popular JAR file opener is JAR Runner, by KIllerApplets.com. You can check it out if you prefer.

4. Run a JAR file in cmd

1. Input cmd in the Search tab.

2. Select Run as administrator to run Command Prompt with full privileges.

search for cmd

3. Then input the following command (replacing pathtofile from the example with the actual path of the file you need to run): java -jar c:\pathtojarfile.jar

command to open jar file

4. Press Enter.

5. 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.

Another easy option is to run a JAR file in cmd, your PC’s built-in command-line tool. All you need to do is input a command while running the app with admin rights, and the file will be opened.

The command-lie app is crucial for debugging and installing apps but if it doesn’t work, learn how you can fix Command Prompt in Windows.

5. Add a third-party JAR executor to Windows

  1. Visit the JARX website and click on the Jarx-1.2-installer.exe file to download it.
  2. Download and click on the file to start the installation, then select the Close button when it’s finished.
  3. Now you can just double-click any JAR file to start it like a normal executable file. The JAR file will be executed.

There are also executor programs for Windows like JARX that enable you to run .JAR files the same as any other program.

Read more about this topic

  • What is Microsoft Coffee and is it real or not?
  • Security Settings Blocked Self-signed Application [Fix]

How to get a JAR file for your favorite app?

There are lots of websites that offer free JAR versions of any application you can think of and we’re going to provide a simple example for Instagram.

  1. Go to a website that offers JAR file downloads like JAR Download. Proceed with caution because not all such websited offer clean content so you should double-check it with an antivirus and scan the files on arrival before using them.
  2. Click on the Java version of the app you’re looking for. In our case, the Instagram Java.
  3. Now hit the Download button and by using our guide above, you already know how to open the JAR and use the contents.

If you’re having trouble or you receive an error, learn what to do if you’re unable to access JarFile on Windows 10.

We hope that our guide helped you with all the information needed to run JAR files in Windows or even convert them if needed.

For any other issues, we also have another guide that will help you if JAR files are not opening on Windows 10.

If you have any other suggestions on how to run a JAR file, or questions about the topic, leave them in the comments section below and we’ll be sure to take a look.

newsletter icon

Содержание

  • Установка компонента Java
  • Способ 1: Меню Java (TM) Platform SE
  • Способ 2: Запуск в «Командной строке»
  • Способ 3: Эмуляторы Java
    • Sony Ericsson SDK
  • Вопросы и ответы

Как запустить JAR файл в Windows

Установка компонента Java

Чтобы иметь возможность запускать исполняемые файлы JAR без использования эмуляторов, на компьютер необходимо установить платформу Java. Устанавливается компонент как обычная программа.

Скачать Java с официального сайта

Способ 1: Меню Java (TM) Platform SE

Сразу нужно отметить, что возможности данного способа ограничены. Хотя последняя версия платформы Java поддерживает запуск файлов JAR, далеко не факт, что конкретная Java-программа будет выполнена. Способ прост: кликните правой кнопкой мыши по файлу JAR и выберите в контекстном меню опцию «Открыть с помощью» «Java (TM) Platform SE binary».
Как запустить JAR файл в Windows 10-2
Если ничего не произойдет, переходите к следующему способу.

Способ 2: Запуск в «Командной строке»

Попробуйте запустить исполняемый файл в консоли, если Java-программа не запустится, — по крайней мере, команда запуска вернет описание ошибки, по которому можно будет установить характер проблемы.

  1. Запустите из контекстного меню или системного поиска «Командную строку» или «PowerShell» (можно с обычными правами).
  2. Как запустить JAR файл в Windows 10-3

  3. Сформируйте и выполните команду вида java -jar "D:\executablejarfile.jar", где содержимое кавычек – это путь к исполняемому файл JAR.
  4. Как запустить JAR файл в Windows 10-4

Способ 3: Эмуляторы Java

Лучше всего для запуска приложений Java использовать специальные программы-эмуляторы, из которых самым известным, универсальным и наиболее функциональным является KEmulator Lite. В настоящее время официальный сайт разработчика недоступен, но приложение по-прежнему можно найти в свободном доступе в интернете. Рекомендуем использовать русифицированную портативную версию эмулятора.

  1. Скачайте архив с программой, распакуйте в удобное расположение и запустите исполняемый файл KEmulator.exe.
  2. Как запустить JAR файл в Windows 10-5

  3. Выберите в меню «Файл»«Загрузить jar…» и укажите путь к файлу приложения или игры JAR.
  4. Как запустить JAR файл в Windows 10-06

Если файл не запустится или эмулятор выдаст ошибку, возможно, что-то не так с самим JAR-файлом либо для полноценной работы эмулятора требуются дополнительные компоненты, в частности Java SE Development.

Sony Ericsson SDK

В качестве альтернативы маловесному KEmulator Lite можно попробовать полноценную платформу виртуализации Java-приложений Sony Ericsson SDK. Официальный сайт разработчика более недоступен, однако эмулятор по-прежнему находится в свободном доступе. Также для этого понадобится набор библиотек Java SE Development Kit и утилита JADMaker, которую также придется поискать на просторах интернета.

Скачать Java SE Development Kit с официального сайта

  1. Скачайте Sony Ericsson SDK, Java SE Development Kit (рекомендуется версия 8u191 x86) и JADMaker.
  2. Установите сначала Java SE Development Kit, а затем Sony Ericsson SDK. Инсталляцию следует выполнять с настройками по умолчанию, если вдруг эмулятор попросит добавить себя в исключения брандмауэра Windows, на это нужно дать согласие. Архив с утилитой JADMaker распакуйте в удобное расположение, она понадобится позже. В начале установки Sony Ericsson SDK появится окошко с предложением автоматического обнаружения каталогов Java SE Development Kit, нажмите в этом окошке «Да».
  3. Как запустить JAR файл в Windows 10-7

  4. Установив набор библиотек и эмулятор Sony Ericsson, зайдите в меню «Пуск» и выберите опцию «Sony Ericsson»«Default Device Selection».
  5. Как запустить JAR файл в Windows 10-8

  6. В открывшемся диалоговом окне выберите модель виртуального мобильного телефона, который станет использоваться по умолчанию.
  7. Как запустить JAR файл в Windows 10-9

  8. Запустите утилиту JADMaker и перетащите на ее окошко файл JAR, который будет преобразован в файл JAD. По умолчанию сконвертированный файл сохраняется в исходную папку.
  9. Как запустить JAR файл в Windows 10-10

  10. Откройте опять меню «Пуск» и запустите эмулятор, выбрав опцию «Sony Ericsson»«Run WIDP Application».
  11. Как запустить JAR файл в Windows 10-11

  12. В открывшемся окне обзора укажите путь к сконвертированному в JAD файлу JAR.
  13. Как запустить JAR файл в Windows 10-12

  14. В результате откроется окно эмулятора с названием Java-приложения. Чтобы его запустить, нажмите кнопку «Launch».
  15. Как запустить JAR файл в Windows 10-13

К сожалению, использование даже такого мощного инструмента как Sony Ericsson SDK не гарантирует, что Java-приложение будет сразу же успешно запущено. Успех или неудача будут зависть от ряда факторов, как то: совместимость версии Java-приложения с эмулируемым мобильным устройством, а также сборки Windows 10. Так, по каким-то причинам в последних сборках этой системы платформа Sony Ericsson SDK работает некорректно.

Еще статьи по данной теме:

Помогла ли Вам статья?

Steps to run a JAR file on Windows, Mac or Linux

To run a JAR file on Windows, Mac or Ubuntu machines, follow these steps:

  1. Verify that Java is installed on your computer
  2. Confirm the computer’s PATH variable includes Java’s \bin directory
  3. Double-click the JAR file if auto-run has been configured
  4. Run the JAR file on the command line or terminal window if a double-clicking fails

If you do not have Java installed, and the PATH variable is not set correctly, attempts to run a JAR file on Windows or Ubuntu will result in a ‘Java not recognized‘ error.

Run JARs in the Java JDK

To run a JAR file, you must install the Java JDK or JRE on your computer.

Why does double-clicking not run my JAR file?

Some Java installers configure Windows or Ubuntu to run Java JAR files when they are double clicked, but not every installer supports this configuration.

Furthermore, it is possible that you didn’t select the JAR double-click functionality during the Java install.

Is every JAR file executable?

Keep in mind that not every JAR file is runnable. Some JAR files are just support files intended to be used by other Java apps.

For a JAR file to run, the JAR itself must contain at least one class that has a runnable main method.

Furthermore, the class with the main method must be listed as the main-class in the JAR’s manifest file. If not, the class must be explicitly stated on the command line when the JAR is run.

How do you run a JAR at the command line?

As long as you have Java installed, and the PATH variable points to the \bin directory of the JDK, you issue the following command to run a JAR file at the command line:

java -jar jarfilename.jar

This Java JAR run command assumes the JAR in question is located in the current folder. If the JAR file to run is located in a different folder, you’ll need to provide a full path to the file.

Commands to create, extract and run JAR files

Function Java JAR command
Run a JAR file  jar -jar jarfilename.jar
Create a JAR file  jar cf jarfiletocreate.jar file-list
Open a JAR file  jar xf jar-file-to-open.jar
Run a JAR without a manifest  java -cp jarfilename.jar com.example.MainClass

What is inside a JAR file?

JAR files are simply ZIP files that contain all of the resources required to run a Java application.

A JAR file typically contains:

  • Java source files
  • Property files
  • XML files
  • Image files
  • A manifest file

What does JAR stand for?

The term JAR is an acronym built from the words: Java Application aRchive.

The term ‘archive’ is really key to understanding what a JAR file is. The JAR file encompasses every file required to support an application, zipped up and compressed into a single, archive file.

The Java JAR file uses a standard compression algorithm used by all of the most popular tools. A Java JAR file is really just a ZIP file with a .jar extension.

How do I extract the contents of a JAR file?

If you look inside at its contents, you can open a JAR file and extract its contents with any standard ZIP or decompression utility.

Popular JAR file opener tools include:

  • WinZip
  • Windows Extractor
  • Gzip
  • WinRAR
  • 7-Zip

Run and open JAR file

You can open Java JAR files with any Zip utility such as 7-Zip or WinRAR.

You can also open a JAR file in Windows PowerShell or an Ubuntu Terminal window with the following command if you have the JDK installed:

jar xf name-of-jar-file.jar [files-to-open]

Why do I get a ‘Could not load main class’ error when I run my JAR?

Not all JAR files are meant to run. Some are just standard libraries with no execution capabilities at all.

If you try to execute a JAR file that is not meant to be run, you will get an error message that says:

Java JAR error: Could not find or load main class ...

Could not load main class fix

If you get this error when you run a JAR that should be executable, the problem could be one of these issues:

  • The main-class to run was not listed in the runnable JAR file’s manifest file;
  • The JAR’s manifest file is missing; or
  • The JAR file distributor wants you to specify the main-class on the command line.

If you know the Java class that should act as the entry point of a runnable JAR, you can explicitly specify that file at the command line as follows:

java -cp jarfilename.jar com.example.EntryPointClass

Notice the flag to run the JAR file has changed from -jar to -cp.

When the main-class is not specified in the manifest file, you must use the classpath flag (-cp), not the -jar flag.

Running executable Java JAR files

JAR files are an excellent way to distribute and deploy cross-platform applications written in Java.

To run JAR files, first make sure you have Java installed, your environment is properly configured, and the JAR file’s manifest file lists the application’s entry-point. With all of these puzzle pieces in place, your Java JAR file will run without issues.

  • Runtimepack lite для windows 10
  • Rustic windows special edition 2k
  • Runtimeerror uvloop does not support windows at the moment
  • Runtimebroker exe что это за процесс windows 10
  • Rust desk server установка windows