0

I started with Java yesterday. I installed Eclipse, JDK and JRE and I did the HelloWorld tutorial. I followed the tutorial and it runs correctly on Eclipse. Now I want to transform it on a runnable .jar file, so I go to Export, i create it, and it apperas on the desktop.

So when I try to doubleclick it (opening it with javaw), it returns the busy cursor icon and nothing happens. On the other hand, if I open it form cmd java -jar HelloWorld.jar, it works properly. Is it normal? What can I do?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Melecio
  • 1
  • 1
  • 5
  • Already answered in here - http://stackoverflow.com/questions/8784300/executable-jar-doesnt-start-normally – hImAnShU Sep 22 '13 at 10:13
  • When double-clicking on the jar Java opens it in `javaw.exe`, which doesn't show console output. Your code runs, you just can't see it. You can get the same result by running `javaw -jar HelloWorld.jar`. – PurkkaKoodari Sep 22 '13 at 10:15

1 Answers1

1

Just like Pietu1998 said, javaw.exe will actually run your program but not open a console window. This is because javaw.exe is meant to run GUIs which obviously does not need a command prompt. See this question for what is the difference between java.exe and javaw.exe.

Even

javaw -jar HelloWorld.jar

on the command prompt will look like nothing happens. Redirect the output to a file and you'll see that your program actually ran:

javaw -jar HelloWorld.jar > HelloWorld.txt

The output of your program will be in the file HelloWorld.txt.

Usually all java programs do not rely on just double clicking to run but come with a kind of a launcher which prepares the environment - notably setting up the classpath - for your app an then runs it. It is platform dependent and if the platform allow to run it using double click then it will be run that way. Such a launcher could be just a simple script: .bat, .cmd, .sh or an executable .exe. For example, if you look at the folder where you have installed eclipse then you'll find a eclipse.exe file (assuming your platform is windows). Creating such a launcher is also easy and is explained in this question.

Community
  • 1
  • 1
A4L
  • 17,353
  • 6
  • 49
  • 70