Run jar program 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

  1. Open the 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.
  3. Click Choose another app and then select to open it with Java(TM) Platform SE binary.
  4. Click the Always use this app to open JAR files check box.
  5. Press the OK button to close the menu.
  6. 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

  1. Press the Win key + X hotkey and select Command Prompt (Admin) to open it as administrator.
  2. 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
  3. 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.
Читайте также:  Linux удаление файлов каталог

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.

Читайте также:  Сменить vpn для windows

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)

Run a jar file using windows scheduler

I have jar file which I want to run from windows scheduler in windows 7

I have Given the path of java.exe in path/script and -jar c:\abc\ab.jar in the arguments field.

But it does not run. I have also tried it with help of a bat file, but it does not run. What is needed to be done to run the jar file?

My jar file creates files and updates a database.

4 Answers 4

Run a java jar from Task Scheduler (Windows 7 Professional 64 bit)

I’ll be configuring it to run every 5 minutes.

Step 1, install java, make sure it is available from commandline

You should be able to run your java jar from the bare cmd commandline. Specify the full java directory like this: (This is the command I used)

Step 2, Open task scheduler:

In the Start menu search bar, search for «scheduler» and «Task Scheduler» should pop up. It is buried in the control panel: Control Panel -> System And Security -> Administrative tools -> Task Scheduler.

Step 3, make a new scheduled task:

In the left pane, right click «Task Scheduler Library». Choose: «New Basic Task». Give it any name.

Choose next. Click «Daily», (the configuration for re-runs every minute will be done later).

Choose next. Recur every 1 day. Have it start a 5 minutes from now. choose next. Click «Start a program».

Step 4, configure your java to run:

In the «Program/script» box put the full path to your java, your path may be different. Double check with cmd command where java

In the «Add arguments» box put this:

Click next, click finish.

Step 5, Right click your new task for further configuration:

Right click your item -> Properties.

Choose the bubble: «Run whether user is logged in or not»

Under the «triggers» tab. Select your Daily task and choose Edit.

Step 6, configure the repeat-task triggers

Begin the task: «On a schedule».

Choose Repeat task every: «5 minutes». Choose the enabled checkbox. Click ok. Save.

You will be prompted for your windows username and password. Add and press OK.

Step 7, ensure it is working

Wait 5 minutes for it to run. Or force run it by right clicking -> Run.

Right click your task, choose properties. Choose «History» tab.

There should be a row there revealing when it ran. If you want to know if it completed successfully, you’ll have to pipe your output to a log file.

Step 8, see if it survives a reboot

Reboot the computer, and see if it stays on. If it does you are done.

Читайте также:  How do you switch from mac os to windows

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:

  1. Open a notepad.exe
  2. Write : java -jar Example.jar
  3. Save it with the extension .bat
  4. Copy it to the directory which has the .jar file
  5. 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.

Оцените статью