I can't open .jar file on Windows 10 (I have tried everything like reinstalling Java and setting the default app to open it to be javaw.exe) and I don't exactly trust jarunner/jarfixer so I want to make a batch program which would detect whenever a .jar is being opened it would get the path of it and would run java -jar [pathtofile].
You'll need to execute this as administrator:
ASSOC .jar=jarfile
FTYPE jarfile=c:\java\java.exe -jar "%1" %*
setx PATHEXT "%PATHEXT%;.jar"
Just put the correct path to the java.exe . Mind that you'll have to keep all your dependencies in the %classpath% vatiable.
More for ASSOC and FTYPE commands.
I am not sure if this is related, but I used this tool http://launch4j.sourceforge.net/ to make .exe from .jar
Related
I am having various .jar files in my system.
I have the JDK and JRE installed.
Most of jar files run on double clicking, but there are 2 - 3 jar files which do nothing on clicking. Help me.
By the way I am using windows 10 64 bit
Problem:
I could not start JAR files just by clicking on them in Windows 10.
I was messing around with the "control panel" ... forget it.
What I've found out:
Start a command line (cmd) as an Administrator
Check your file type association:
ftype jarfile
assoc .jar
I had to change my java path to a different one
ftype jarfile=C:\myjavapath\javaw.exe -jar "%1" %*
Which basically means, that if someone starts a jar file, the command would be:
C:\myjavapath\javaw.exe -jar "example.jar" parameter1 parameter2
For me, I also had to change my .lnk files to only contain the name of the jar file, not the whole command. Type in the whole path of the jar file in the "target" field in the properties of the link file (.lnk).
You can debug it in the Command Prompt.
Open start, type in CMD.exe, hit enter
Then, type in
java -jar "path\to\file.jar" without the quotes
or
java "path\to\file.jar"
You should be able to see an output log of what is happening that is making the jar file not execute properly
Your Manifest file should contain a line:
Main-Class: classname
See "Setting an Application's Entry Point".
I just created a jar file using jdk7. I tried running it but kept getting an error. It turned out it was pointing at a jre6 and not the jre in jdk7. So, I used the following command to change it
ftype jarfile = "C:\path to jre\bin\javaw.exe" -jar "%1" %*
After that, I tried to double click on my jar file again, but it popped up a window asking me to choose a program to open it with. When I chose the same javaw.exe file as above it runs but exits immediately without doing anything. I can run it fine in cmd by doing the java -jar file.jar command. I even tried deleting the .jar registry key, but that just got me back to the point where it asked me to choose a program to open with. I'm running windows 7 ultimate if that matters.
EDIT:
In the registry there are 3 subkeys: OpenWithList, OpenWithProgids, and UserChoice. I've changed all the defaults to the path above except UserChoice which won't let me edit it from regedit. When I delete that and try to run the jar file, it opens up the choose a program to open with window again. For some reason it ignores the other registry keys
OK, I found the answer somewhere else but ran into this issue again so came here via google.
The solution is...
Open up regedit.exe
Either search for "jre6" or follow this: HKLM->SOFTWARE->Classes->jarfile->shell->open->command
Change the Data field to the directory of the javaw.exe file that's in your JDK directory.
For the love of God, don't forget to put the weird [-jar "%1" %*] parts on the end of it.
Enjoy outsmarting Oracle.
Hopefully this'll save some people a bit of time.
This happened to me when I installed the JRE6 plugin for Chrome, though it could happen when installing any other JRE I guess.
I fixed it by going to regedit and searched for jre which brought up...
HKEY_CURRENT_USER/Software/Classes/Applications/javaw.exe/shell/open/command
I changed the REG_SZ
from: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" "%1"
to: "C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*
When windows asks you for a program to run it against it won't insert the needed -jar argument in the command line.
If it's asking you for the exe in which to run it then that means somehow your JRE isn't associated with the .jar extension. You'll need to modify the .jar file registry entry so that it runs c:\path_to_jre\bin\javaw -jar %1 in order for it to work.
It used to be under File Explorer > Tools > Folder Options > File Types.
Then look for .jar in there. You should find a text field that shows the executable to run and the command line arguments. That's what you want to modify. You can also do it in the registry editor too, but I've forgotten the HKEY variable path. I'm sure this KBA will help:
support_microsoft_kb_950505
Check if the file type jarfile is actually registered with the *.jar extension using
assoc .jar
Seems like .jar is not linked to jarfile.
I'm not sure exactly why none of the solutions worked, but I reinstalled jre7 and it works now.
Isn't it easier to change your java version to you rnew jdk7 by changing the CLASSPATH environment variable? See how here
I have a java desktop application that contains the following code:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
System.out.println("check1");
int intResult = compiler.run(System.in, System.out, foutErrorFile, strvalidatePath);
System.out.println("check2");
When I run the corresponding .jar file of this application by executing "java -jar name.jar", both check1 and check2 gets printed and app works fine.
But when i try to run the jar by double clicking the .jar file, I found that ToolProvider.getSystemJavaCompiler() is returning null. "check2" does not get printed. I dont get proper result from compiler.run().
I did modify the registry entry "\HKEY_CLASSES_ROOT\jarfile\shell\open\command" from
"C:\Program Files\Java\jre1.6.0\bin\javaw.exe" -jar "%1" %* to
"C:\Program Files\Java\jre1.6.0\bin\java.exe" -jar "%1" %*.
This way I'm able to see the console when the app is running.
So why is my program (which runs fine while run using java -jar command) malfunctioning when I run the .jar file by double-clicking?
I got my problem solved. While double-clicking, the command that gets executed is the one specified in registry entry. In my case the registry entry "\HKEY_CLASSES_ROOT\jarfile\shell\open\command" is:
"C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
This means its uses the javaw.exe app in the JRE directory to execute the program. My JRE directory lacked one .jar file named Tools.jar in its lib folder. This was essential to acquire the compiler during the program execution.
I copied the missing jar file from the JDK directory lib folder to the same in JRE directory. This solved my problem. Thank you to all for helping.
I think the best way is create a .bat file who calls java -jar name.jar
I have a problem with an executable jar file. When I launch my jar file with Windows command line, all is good :
java -jar updater.jar
When I double click on my jar file, nothing happens.
This problem appeared when I added graphic support to my application (org.eclipse.jface and org.eclipse.swt).
My MANIFEST.MF :
Main-Class: Updater
Class-Path: libs/
Thank you in advance
It will not open with double click, because that would be like you typing javaw updater.jar in cmd.
The thing you need to do is write a wrapper for the thing. Maybe VisualBasic as it is easy to understand. You can write an updater in it and use AmazonAWS to host your update files. That's what I do, and I reccomend you to do that too.
Solution (thx a_horse_with_no_name for clues) :
With an application which use platform dependent component (like org.eclipse.swt.win32.win32.x86_64_3.102.1.v20130827-2048.jar), set ftype jarfile to JRE that correspond to your architecture (32 or 64 bit) in commands line prompt (run as administrator) :
ftype jarfile="C:\Program Files (x86)\Java\jre7\bin\javaw.exe" -jar "%1" %*
or
ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
All works fine now, thank you !
This pretty much has me defeated.
On XP and earlier versions of Windows you could customise Open With filetypes to include java - jar "myjar.jar", but on Vista this functionality seems to have been removed. I can of course create a .bat file to launch my application, but is it possible to make Vista execute a .jar as required?
You can do it from the command line with 2 utilities.
The first one, ASSOC, is used to create a file association. To verify if there is one defined for JAR type :
>assoc .jar
.jar=jarfile
If not found then create it with :
>assoc .jar=jarfile
The next step is to define the association. This is done with FTYPE.
To verify if one is already defined , type
>ftype jarfile
jarfile="C:\Program Files\Java\jre1.5.0_10\bin\javaw.exe" -jar "%1" %*
Again if not found or the wrong JRE is used, use FTYPE to fix the problem
>ftype jarfile="C:\Program Files\Java\jre1.5.0_10\bin\javaw.exe" -jar "%1" %*
Use the software JarFix >= 1.1.0 .
There is Vista support included and it "recovers" the .jar association!
download for example here:
http://www.softpedia.com/get/Others/Miscellaneous/Jarfix.shtml