jar launches from command prompt, but hangs on double-click

  • Thread starter Andrew C. Chase
  • Start date
A

Andrew C. Chase

Hi all,

I've got a really strange problem vexing me.

I have an application packaged in a jar that launches fine when I
launch it from the command prompt with the command: java -jar
myfile.jar

However, when I double click on that same file from within explorer,
the program hangs somewhere in the constructor. The jar is in the same
directory in both cases, and is the only file in the directory in both
cases.

I've been debugging by putting JOptionPane.showMessageDialog commands
throughout the code so that I can see what is going on when I
double-click the jar. I have narrowed it down to the creation of a new
object which inherits from JToolbar. When I try to create the new
object, the program hangs. I can still see the javaw.exe in the Task
Manager, but thats it, no other response. I've tried putting
showMessageDialog calls in the constructor of the class which the
program is hanging on, but those never get called. The class which the
new object is from is has nothing special in it, in fact, the previous
object that is created is also from a class extending JToolBar, with
an almost identical structure.

When I comment out the line where the program is hanging (and the
corresponding line where the new JToolbar is added to the JFrame) the
program will load, but it looks like it is in a bad state because the
repaint does not work properly. This commented version of the code
works fine when started from the command prompt with java -jar

I've tried "open with" with multiple jre's to no avail...

Any suggestions?

Thanks,
Andrew
 
B

Brian Pipa

Can you add in a logger and have it log everything (verbose) to a log
file then you can take a look at the log file and maybe see what's going on?
 
M

Mike Schilling

Andrew C. Chase said:
Hi all,

I've got a really strange problem vexing me.

I have an application packaged in a jar that launches fine when I
launch it from the command prompt with the command: java -jar
myfile.jar

However, when I double click on that same file from within explorer,
the program hangs somewhere in the constructor. The jar is in the same
directory in both cases, and is the only file in the directory in both
cases.

I've been debugging by putting JOptionPane.showMessageDialog commands
throughout the code so that I can see what is going on when I
double-click the jar. I have narrowed it down to the creation of a new
object which inherits from JToolbar. When I try to create the new
object, the program hangs. I can still see the javaw.exe in the Task
Manager, but thats it, no other response. I've tried putting
showMessageDialog calls in the constructor of the class which the
program is hanging on, but those never get called. The class which the
new object is from is has nothing special in it, in fact, the previous
object that is created is also from a class extending JToolBar, with
an almost identical structure.

When I comment out the line where the program is hanging (and the
corresponding line where the new JToolbar is added to the JFrame) the
program will load, but it looks like it is in a bad state because the
repaint does not work properly. This commented version of the code
works fine when started from the command prompt with java -jar

I've tried "open with" with multiple jre's to no avail...

Any suggestions?

I would write out the values of all of the java.* properties listed on the
following link, and see how they differ between the two cases.

http://java.sun.com/docs/books/tutorial/essential/system/properties.html
 
E

E.Otter

Sounds like you are hitting a problem with javaw.exe or have more than one
version of the java virtual machine installed and the wrong one is getting
used when double-clicking

First, make sure you only have 1 version of the j2sdk/jre installed. I
installed the j2sdk 1.3 for a work-related project and then installed the
j2sdk 1.4 for a class I taught. Turns out that even though my "java plug
in" was set to the j2sdk1.4, the windows registry mapped the jarfile to be
opened with the 1.3 j2sdk. This caused jar files to hang when I
double-clicked them.

If you are comfortable with the windows registry and using regedit.exe check
these two locations:
HKEY_CLASSES_ROOT\jarfile\shell\open\command
make sure the path for javaw.exe is correct

Also check under:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Current Version\App Paths
There may or may not be a folder for java.exe and javaw.exe here, but if
there is make sure the path is to the correct executable.

Another possibility is that some people experience problems with javaw.exe,
which is supposed to be just like java.exe execept that it does not pop open
a command prompt window. To double-check that its really this kind of
issue, click the Windows Start button, then click Run and type in the
command line (for example, java -jar c:\stuff\blah.jar) to run your "jar
program". Then try it with: javaw -jar c:\stuff\blah.jar
If it hangs with javaw and not java, then you can change the Windows
registry for the HKEY_CLASSES_ROOT\jarfile\shell\open\command to use
java.exe instead of javaw.exe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top