How to run jar file on windows

How to run jar file on windows

What Are JAR Files?

How to Run JAR Files on Windows 10?

Way 1. Add Java to Windows

The first way you can try to open JAR files is to add Java to Windows. Without it, Java apps will not run on Windows and the JAR files also will not be opened.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Way 2. Open JAR Files with JAVA Platform SE Binary

In order to run JAR files, you can also choose to run it through the JAVA Platform SE Binary.

Now, here is the tutorial.

After all steps are finished, you can open JAR files on Windows 10 through the JAVA Platform SE binary.

Way 3. Open JAR Files with Command Prompt

Now, here is the tutorial.

Then, it will open the executable JAR file so long as it contains manifest file to specify the applications entry point.

Way 4. Add a Third-Party JAR Executor

As for how to run JAR files, you can use the third-party JAR executor and there are various JAR executors on the market. So, in order to run the JAR file, you can download a third-party JAR executor. After that, you can open the JAR file successfully.

Final Words

About The Author

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Tina is a technology enthusiast and joined MiniTool in 2018. As an editor of MiniTool, she is keeping on sharing computer tips and providing reliable solutions, especially specializing in Windows and files backup and restore. Besides, she is expanding her knowledge and skills in data recovery, disk space optimizations, etc.

On her spare time, Tina likes to watch movies, go shopping or chat with friends and enjoy her life.

Running JAR-Packaged Software

Now that you have learned how to create JAR files, how do you actually run the code you packaged? Consider these scenarios:

This section will cover the first two situations. A separate trail in the tutorial on the extension mechanism covers the use of JAR files as extensions.

Applets Packaged in JAR Files

To start any applet from an HTML file for running inside a browser, you use the applet tag. For more information, see the Java Applets lesson. If the applet is bundled as a JAR file, the only thing you need to do differently is to use the archive parameter to specify the relative path to the JAR file.

As an example, use the TicTacToe demo applet. The applet tag in the HTML file that displays the applet can be marked up like this:

If the TicTacToe demo was packaged in a JAR file named TicTacToe.jar, you can modify the applet tag with the addition of an archive parameter:

The archive parameter specifies the relative path to the JAR file that contains TicTacToe.class. For this example it is assumed that the JAR file and the HTML file are in the same directory. If they are not, you must include the JAR file’s relative path in the archive parameter’s value. For example, if the JAR file was one directory below the HTML file in a directory called applets, the applet tag would look like this:

JAR Files as Applications

You can run JAR packaged applications with the Java launcher (java command). The basic command is:

The -jar flag tells the launcher that the application is packaged in the JAR file format. You can only specify one JAR file, which must contain all of the application-specific code.

Before you execute this command, make sure that the runtime environment has information about which class within the JAR file is the application’s entry point.

To indicate which class is the application’s entry point, you must add a Main-Class header to the JAR file’s manifest. The header takes the form:

The header’s value, classname, is the name of the class that is the application’s entry point.

For more information, see the Setting an Application’s Entry Point section.

When the Main-Class is set in the manifest file, you can run the application from the command line:

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

12 Answers 12

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

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.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

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.

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:

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Eclipse Runnable JAR File

Create a Java Project – RunnableJAR

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

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

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/*

Note: com/lynda/olivepress/* means including the other two packages mentioned above, before point 1)

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

If you don’t want to deal with those details, you can also use the export jar assistants from Eclipse or NetBeans.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

Introduction

There are several ways to run java application:

In this answer I’ll explain, how to run a jar if you have to run it manually, give hints to resolve common problems.

Classpath or module path

Classpath

Try the following:

Module-path

Try the following command:

If it fails with FindException :

Troubleshooting

UnsupportedClassVersionError

Supplying dependencies

An Error or Exception is thrown when an application run with missing or out of date dependencies. Common exceptions and errors:

To supply dependencies:

I tried the ftype hint, no success:

I reinstalled the JDK 7 64-bit, no success.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

18 Answers 18

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

If you have previously used the right click and opened with \path\to\your\javaw.exe then you will need to remove the following registry key.

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

You may also run it from the Command Prompt (cmd):

How to run jar file on windows. Смотреть фото How to run jar file on windows. Смотреть картинку How to run jar file on windows. Картинка про How to run jar file on windows. Фото How to run jar file on windows

I tried all above steps to resolve the problem but nothing worked. I had installed both JDK and JRE.

I was finally able to fix the problem by changing javaw.exe path (from JDK\bin to JRE\bin) in registry editor.

Go to HKEY_CLASSES_ROOT\jarfile\shell\open\command, the value was,

I changed it to,

and it worked. Now the jar file can be opened by double click.

And jar files still fail to open (in my case it was like I never double clicked):
open the Command Prompt (to be safe with admin rights enabled) and type the following commands:

Read through the output generated. You may discover an error message.

I had the same issue: if I doubleclick on a jar executable file, and my Java application does not start.

So tried to change manually also registry key, but it didn’t help me. Tried to reinstall JDK newer/older without any result. (I have several versions of Java)

What says Johann Nepomuk Löfflmann:

Notice: my OS is Windows 10, but logic is the same for 7, 8 and so on.

Run a JAR file using a specific JRE

Is there a way on Windows to run a JAR file using a JRE located in a specific folder? Similar to the way Eclipse looks for its JRE in some path you give to it. Either some windows executable code (C or C++) or a Batch file will do the job. Thanks!

5 Answers 5

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

A JRE directory has a bin/java.exe.

You can run a jar from that JRE simply with

Run from command

(or use javaw.exe to return to command prompt immediately after launch of the JAR)

Or set environment variables

Many start scripts respect variables JRE_HOME and JAVA_HOME for JRE and JDK respectively. Some don’t like spaces, so use short path convention ( C:\Progra

On 64bit systems:
Progra

1 = Program Files
Progra

2 = Program Files (x86)

Or set file associations

to launch JARs by double clicking. Unfortunately, the GUI (Control Panel\All Control Panel Items\Default Programs\Set Associations) is quite lousy, so you have to do it in Registry.

This is my favorite method to choose 32/64bit JRE, when the Control Panel setting is ignored.

In my case for 64bit env:

Mind the quotes: javaw path contains space; the JAR path can contain spaces; passed parameters are space separated.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *