Running Jar File on Windows

Running JAR file on Windows

Easiest route is probably upgrading or re-installing the Java Runtime Environment (JRE).

Or this:

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

Which was stolen from here: http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html

Java Windows. why can I run a jar file on command prompt but not double clicking it

You have to tell java to execute your file with javaw.exe as told by @Carcigenicate

  1. Start "Control Panel"
  2. Click "Default Programs"
  3. Click "Associate a file type or protocol with a specific program"
  4. Double click .jar
  5. Browse C:\Program Files\Java\jre7\bin\javaw.exe
  6. Click the button Open
  7. Click the button OK

Run Jar file on PC at startup

Try the following:

Write a batch file as follow ans save it as *.bat or *.cmd:

start javaw -Xmx200m -jar C:\Path\to\jarfile\TheJar.jar

Save the file created in the startup folder for all users, which should be C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp

It is important to pay attention on the folder, because if your used Windows + R and shell:startup shortcut like I usually do, it will only work for the current logged user.

How can I execute .jar file from the terminal without specifying its name

I am not sure it would be a good idea to just run everything in a directory, but you could:

FOR %A IN ("*.jar") DO (java -jar "%~A")

Problem with running jar file in windows10

Your code: proc.StartInfo.FileName = jarName; tells Windows to run the .jar file with whatever it has associated as a handler for jarfiles. It is the same as double clicking.

So the fact that both methods don't run means the Java runtime on Windows isn't a registered handler to the jarfile. Depending on the JRE flavours you have installed, most of the Open JRE installers don't do it. AdoptOpenJDK has started including the jarfile handling option into the installer i think some time this year(?).


Option 1

Fix the jar file association. This should make it work on your other computer, but you would need to do it on every other computer that are having the same issue.

On the bright side, this will also fix double-clicking on the jar, something that Option 2 below doesn't do.

You have a few options to do this:

  • Use a JRE/JDK installer that does it for you (e.g. AdoptOpenJDK's installer).
  • Do it manually. This particular answer (not the one marked as accepted) should work.
  • If you're not against running a third-party tool made by a random stranger on the internet, jarfix would automate the manual way above.

Option 2

Make your program trigger Java even if it's not currently associated with jarfiles.
This will likely make it run on more computers, but won't fix your jar double-click issue.

This requires Java to already be installed and is in your OS's PATH. To test this, fire up a command prompt, and run java -version. If you get a response, keep reading. If you don't, you need to look up how to include Java in your PATH.

Now, in your StartInfo, you want to call java and not your jarfile directly:

proc.StartInfo.FileName = "java";

You then specify your jar as part of the argument:

proc.StartInfo.Arguments = " -jar " + jarName + " " + ...the rest of your args.

You can replace "java" with "javaw" if you know you'll only ever run it on Windows.

Running JAR files in Windows 10

This is simply a problem with the UAC level in windows, not specific to win 10.

I could use batch script from this link to prompt for the Admin privileges when executing the jar.



Related Topics



Leave a reply



Submit