EnderEgg
EnderEgg

Reputation: 335

CMD is closing and doesn't let see the result (Java, running a .jar from .bat)

So, I made my first little program, if you can call it a program. I exported it from eclipse as a .jar file, and I'm running it with a .bat file. I don't think the problem is there, but here is what I wrote in the .bat:

start java -jar apples.jar

What I did to solve the problem was:

System.out.println("Press any key and then enter to exit"); 
String end = in.next();

But even so, it just closes. Thanks. If you want the see all the code, say. But it's mainly a big ass menu to finally do a small operation.

Upvotes: 2

Views: 3353

Answers (2)

ilgazer
ilgazer

Reputation: 110

use java -jar apples.jar and

System.out.println("Press enter to exit"); 
String end = new Scanner(System.in).nextLine();

to make it only needed to enter to exit

Upvotes: 1

Isaac
Isaac

Reputation: 16736

The start command on Windows causes the java.exe process to start in its own window; that window gets closed immediately when the java.exe process ends.

So, you have two options:

  1. Don't use the start command. Remove the start command from the beginning of the command line.

  2. Add a 'pause' statement to your batch file.

Upvotes: 2

Related Questions