Ľubomír Skirka
Ľubomír Skirka

Reputation: 37

Automatic open command prompt after run jar app

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.

Upvotes: 0

Views: 287

Answers (2)

mad_manny
mad_manny

Reputation: 1091

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.

Upvotes: 0

Aleksandar Marinkovic
Aleksandar Marinkovic

Reputation: 519

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)

Upvotes: 1

Related Questions