2

I'm in the process of porting simple console apps written in C++ to Java in order to show how similar the languages are, and how code can be ported. I've exported executable JARs for the programs using Eclipse. These JARs work fine when they are run using the java -jar command. However, they do not run properly when executed from windows explorer (double clicked). A console window simply opens and closes rapidly.

The only solution I have found thus far is to use a batch file. Is there any other option?

Sean W.
  • 4,944
  • 8
  • 40
  • 66

5 Answers5

0

Change the open with program to c:\Program files\java\jre7\bin\javaw.exe

0

There are some options:

  1. Sleep a bit when the program is done, so you can read the output.
  2. Call System.in.read() (again at the end of the program), which will wait until you type a char and hits enter.
  3. Create your own little swing terminal, which doesn't close when the application code is done.
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287
  • I should clarify. It should first prompt for input via java.io.Console.getline() it does not even do that. So the problem is not when the program exits, it is that it seems to not run properly at all. – Sean W. Sep 03 '11 at 21:07
0

This seems like the jre used from the command line and from the registry are not the same (this can occur when multiple JRE's are installed)

Have you checked in your windows registry what is the jre used to run the executable jars ? You can find more on the registry settings on sun's site

Binary9
  • 378
  • 1
  • 7
0

Seems to me that your main class does not even gets executed. This would explain the quick open/close of console window.

Or is it possible that another program than java has the "jar" file type? Happened to me after installing a Nokia software.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
0

Using a batch file seems to be my best option. I suppose that's why Eclipse has a launcher.

Sean W.
  • 4,944
  • 8
  • 40
  • 66