0

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.

Vikash Chauhan
  • 792
  • 2
  • 9
  • 18

2 Answers2

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