Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application not running from jar

 
Sunny Kumar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sunny Kumar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This could be a good reference to make executable jars. I spend sometime battling with similar issues, but this articles made it clear.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sunny Kumar
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic