This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Application not running from jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Application not running from jar" Watch "Application not running from jar" New topic
Author

Application not running from jar

Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
I have developed a small UI using Netbeans 5 Beta 2.
Have 2 class files as:
1.Main.java : This files builds up my GUI
2.NewClass : Its sets the UI visible

The problem is when I select Run Project from Netbeans the application executes smoothly, but when I double click on the generated jar file nothing happens.When I tried to execute it from the dos prompt I got the foll message :

I am not understanding how Netbeans is able to run it and still the generated jar file doesn't work.
Where's the problem?
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
With application jars you can either include a classpath in the manifest or type it in when you launch the jar: "java -jar YourApp.jar -cp path". Unzip your jar and take a look at its manifest: I don't think you'll find a classpath entry.


There is no emoticon for what I am feeling!
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Ya..you are right.I checked up the Manifest file and it didn't have the ClassPath entry. So can you please tell me how can it be done in Netbeans?
Secondly, as suggested by you I did try the java -jar with -cp path but it didn't work. I did see the jar files used by my application in netbeans and found that its swing-layout-0.9.jar and so specified the cp path accordingly..but that too didn't help.
And since I will be distributing my application how is it possible to attach all relavant jar files with it?
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
This could be a good reference to make executable jars. I spend sometime battling with similar issues, but this articles made it clear.


All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
NetBeans must have the internal CLASSPATH set correctly for this to work. It just doesn't store the classpath in the jar's manifest file. Does your project include the jar file that this class lives in?

When you use the -jar option, it will ignore the classpath set with the -cp option. If you wish to use the -jar option, the classpath must be set correctly in the jar's manifest. Otherwise, you can include the jar file in the classpath (with the -cp option, for example) and indicate the class to execute as well.

Layne


Java API Documentation
The Java Tutorial
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Originally posted by Layne Lund:
NetBeans must have the internal CLASSPATH set correctly for this to work. It just doesn't store the classpath in the jar's manifest file. Does your project include the jar file that this class lives in?


I am not geting you. As far as I know one can specify the classpath in the Manifest file. Its shown in link given by Alex Kravets,if not then what are you trying to mention in the foll. paragraph (italics) and I didn't get the last part of your question??


When you use the -jar option, it will ignore the classpath set with the -cp option. If you wish to use the -jar option, the classpath must be set correctly in the jar's manifest. Otherwise, you can include the jar file in the classpath (with the -cp option, for example) and indicate the class to execute as well.


I do included my jar file in classpath but still the problem.
Sunny Kumar
Ranch Hand

Joined: Oct 27, 2005
Posts: 57
Guys...Thanks for all you prompt replies.
I have found the cause.
On refering to the Netbeans GUI tutorial, it was mentioned that when the project is build the appropriate jar file will be automatically added in a folder named lib under dist directory.
But in my case the lib folder was not at all created and neither the manifest file had any such entry.
So after correspondingly modifing the manifest file in the projects root folder (which I came to knew later thats it is this manifest file used by netbeans)and building the project, I made the lib folder under dist directory and placed the swing-layout-0.9.jar in it.
Thats it.The application executed smoothly.
Hope this helps to anyone facing similar kind of problem.
Don't know whether its a bug in Beta 2.
 
GeeCON Prague 2014
 
subject: Application not running from jar