opening an eclipse .jar file

T

TrevorBoydSmith

I created the tutorial helloworld project that prints text to a
console. I want to make it into a .jar so that I can double-click and
have it automatically run using the Java Runtime Environment. So I
used the export command and created a .jar file. (making sure to: not
compress, export generated class files and resources.) After those
setting I clicked finish. And expected the .jar file to double click
and open a console application. But nothing happened. I also tried
opening the .jar file in the command line. (This is on windows.)

How do you get a .jar file to work when you double-click? (if you know
a good source to read about this please leave a link on it)
 
B

Brandon McCombs

I created the tutorial helloworld project that prints text to a
console. I want to make it into a .jar so that I can double-click and
have it automatically run using the Java Runtime Environment. So I
used the export command and created a .jar file. (making sure to: not
compress, export generated class files and resources.) After those
setting I clicked finish. And expected the .jar file to double click
and open a console application. But nothing happened. I also tried
opening the .jar file in the command line. (This is on windows.)

How do you get a .jar file to work when you double-click? (if you know
a good source to read about this please leave a link on it)

either wrap it into a .bat file and put a java.exe command in the bat
file to execute the jar or the more appropriate way is to associate .jar
files with javaw.exe in your Windows MIME types so that javaw.exe is
executed to run it just like msword.exe runs for .doc files.
 
L

Lee Weiner

I created the tutorial helloworld project that prints text to a
console. I want to make it into a .jar so that I can double-click and
have it automatically run using the Java Runtime Environment. So I
used the export command and created a .jar file. (making sure to: not
compress, export generated class files and resources.) After those
setting I clicked finish. And expected the .jar file to double click
and open a console application. But nothing happened. I also tried
opening the .jar file in the command line. (This is on windows.)

How do you get a .jar file to work when you double-click? (if you know
a good source to read about this please leave a link on it)

In Windows, when you install the JRE, jar files get associated with javaw.exe.
javaw supresses the console screen. IOW, your program may be running
properly, but you can't see the output. If you want to double-click console
programs and have them visible, change the Windows file association from
javaw.exe to java.exe.

Lee Weiner
lee AT leeweiner DOT org
 
A

Andrew Thompson

I created the tutorial helloworld project that prints text to a
console. I want to make it into a .jar so that I can double-click and
have it automatically run using the Java Runtime Environment. So I
used the export command and created a .jar file. (making sure to: not
compress,

The classes and resources in a jar file can be compressed.

Note that there are a variety of forms of Zip compression
some fo which standard Java does not understand
(e.g. WinZip's 'max. compression' settings), but if you
use the Jar tool to do the compression, you can be sure
that Java can inflate the file.
...export generated class files and resources.) After those
setting I clicked finish. And expected the .jar file to double click
and open a console application. But nothing happened. I also tried
opening the .jar file in the command line. (This is on windows.)

How do you get a .jar file to work when you double-click?

Add a manifest file that specifies the 'main' class.
..(if you know
a good source to read about this please leave a link on it)

<http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Main Attributes>

HTH

Andrew T.
 
T

Thorgull

If you want the quick and easy solution look at this eclipse plugin :
FatJar ( http://fjep.sourceforge.net/ )

This plugin add a command in the context menu of projet ("build fat
jar" or something like that). this command create a jar file with a
manifest and include all dependencies of your project in the jar. The
plugin has a lot of options but the default one's will be just fine in
your case. (just click next next next ...)

To run a jar by double clicking on it in windows you need to associate
the files *.jar with the command "$JAVA_HOME\bin\javaw.exe" -jar "%1"
%* (replace $JAVA_HOME by the path to your jre)
 

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

Forum statistics

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

Latest Threads

Top