I have comand line application in Java. Can I write code for double click on JAR file and app start run in comand prompt(automatic open). Thanks for answers.
Asked
Active
Viewed 187 times
0
-
1you can make a bat file – Madhawa Priyashantha Mar 24 '16 at 11:11
-
And without bat? Only 1 file? – Ľubomír Skirka Mar 24 '16 at 11:13
-
1you can convert jar file to exe .try [exe4j](https://www.ej-technologies.com/download/exe4j/files) – Madhawa Priyashantha Mar 24 '16 at 11:15
2 Answers
1
Did you try this:
Right Click > Properties > Change > C:\Program Files\Java\jre8\bin\javaw.exe
This has been resolved here How to run .jar file by double click on Windows 7 (64)

Community
- 1
- 1

Aleksandar Marinkovic
- 509
- 3
- 7
0
Assuming your problem is, that your jar runs silent in background and you don't see output:
Usually this is not possible using only 1 file and you would need to create a .BAT with the following next to your .JAR:
java -jar jourJar.jar
It's possible to use a wrapper, like Fast Snail suggested.
You still can do it with pure java code using 1 file with something like the following, but it's more a hack.
public static void main(String[] args){
if(args.length > 0 && args[0].equals("instance")){
//start your real application code here
}else{
Runtime.getRuntime().exec(new String[]{"cmd", "java", "-jar", "jourJar.jar", "instance"});
}
}
This will open the JAR and then it creates a new CMD process running the JAR again.

mad_manny
- 1,081
- 16
- 28