I have created a GUI program in Netbeans and I want to be able to distribute the program to run on another machine. I pressed F11 to create the dist folder and it contains the .jar file. It also created a text file that stated that if I wanted to run it from a command line that all I needed to type was...
java -jar "filename.jar"
and it would run. However, when I do this it simply falls thru with no errors. The program runs fine in netbeans. I know that I have to include the swing jar in the classpath and it is there, but it still won't run.
Does anyone know what I need to do to get this thing portable? I want to create a batch file to fire it off.
I know that I have to include the swing jar in the classpath and it is there,
Sorry, I don't know what's wrong with your application, but I do know that the statement I quoted above is wrong.
When you run an application with "java -jar ...", the CLASSPATH environment variable is not used. So it doesn't matter what you set it to. The application gets its classpath from the manifest file, which is inside the JAR.
Also, I wonder what you mean by the "swing jar" - there is no separate JAR file in Java 1.5 that contains the Swing classes.
Glad to see you have got to the stage of producing .jars.
Have you been through the Java tutorial sectionabout .jar files? If you go through that, you will find that the problem is most likely not the .jar itself, but the Manifest. Manifest as in "cargo manifest" on a ship; it tells the computer (or JVM) some details about the .jar. You will find it all in the tutorial.
Take your jar apart (the tutorial tells you how to do that), and open the Mainfest file with a text editor or similar. Does it have the bit about main-class or main-method (I forget which) in? I have just tried it in Eclipse myself, and my .mf file didn't have Main-Class in.
Several possible things to do:
Read through deployment until you find out about manifest files, and what you need to write about main-class. Update the manifest file by hand, and use the jar utility to put that manifest file in your jar.
Go back to Eclipse, and set up a Main class in your project folder. That has in it a public static void main(String args) method, which starts off your application, and nothing else. Then recompilie your .jar file.
See whether the help in Eclipse about .jar and manifest files is any help.
Remember, if you update your manifest file by hand, it is a little like setting a PATH variable. The tiniest spelling mistake and nothing will work.
Joined: Oct 13, 2005
I have tried again and got a package to run from a .jar in Eclipse.
Get package explorer on the left of the window.
Click your package to highlight it.
Click File, then Export.
Click jar then next.
Click the name of the package you are converting to a .jar.
Click which files you wish to export, either class and resource or all. Not source and resource.
enter name and destination
Choose the options at the bottom. Jar files are usualy compressed, in fact with the same algorithm as .zip files.
Tick more options and then next, not finish. You can probably guess what to tick; they seem straightforward.
Click create manifest, but not save or reuse.
Don't click seal. Click browse to find the class with the main method in. Click finish.
It should be possible to seal a .jar, but Eclipse wouldn't let me do it this way.
Joined: Oct 13, 2005
There must be a similar mechanism in NetBeans.
Joined: Jun 03, 2006
Sorry it took so long for my reply.
In Netbeans, when you hit F11 it creates a dist folder and creates teh jars with the Manifest.mf file in it. Because I used the GUI laytool, it uses the swing-layout-1.0.jar file and that has to be part of the total package for distribution. I checked the manifest file adn it points to lib/swing-layout-1.0.jar as needed. If I copy the dist folder to another computer or even another location on the drive say c:\temp and try to run the program from the command line using java -jar thefilename.jar it looks as if it runs it, but simple falls thru and doesn't fire off Java at all nor do I get any errors. The readme file that it creates even says...
"To run the project from the command line, go to the dist folder and type the following:
java -jar "DisConver.jar""
So, I am a bit lost as to how to get it to run. Netbeans WEB page is even vague and tells me the same thing.
unzip your jar file and go look at the manifest and see if it's correct you set the main entry point to your program when you setup the project and I bet you accepted the default and it's not what you want
Joined: Sep 16, 2003
you can set it to what you want by right clicking on the project in the explorer window, go to properties, then go down to the "run" settings
Joined: Jun 03, 2006
Well, I came home and tried it on my box and all is well. The only thing that I can think of is my work box install (Java) is messed up. Thanks for all the tips guys.