• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Executing a jar file

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I want to create a jar file which can be run simply by clicking on it.
Here are the steps which I have followed.
I have created a manifest file which has a listing of main class.
Created jar file using -jar option available in java.
Now the problem is when I try to run this jar file, it gives this error:
Exception in thread "main" java.lang.NoClassDefFoundError:
Though all necessary jar files are included in classpath.
Small Note: When I try to run class files, it runs fine.
Pls help me out.
Thanks and Regards,
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have a problem with your class-path.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YOu have to add one entry for main class in you Manifest.mf file
 
M.K.A. Monster
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have created a manifest file which has a listing of main class.


He says he has added this thing in the manifest file.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you create the jar file?
Does the Jar file structure follows the package structure?
Also, did you run the application using:
java -jar [your_jar.jar] [your_application]
instead of
java -classpath [your_jar.jar] [your_application]
Nick
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have checked my classpath before running also I tried to run this using
java -classpath -jar jarname
but still its not working.
pls help
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that your JAR file contains all necessary classes for your application?
If so, you dont need -classpath.
Nick
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did You put the full qualified name of Your 'main-class' in the manifestfile? You have to do this.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More specifically, you need to put the Class that contains the method:
public static void main(String args[])
in the MANIFEST.
Nick
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have considered all the above things
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One suggestion I don't see here is the Class-Path entry in the manifest file.
Have you tried setting your classpath there. Below is an example
Manifest-Version: 1.0
Created-By: Apache Ant 1.5
Main-Class: Main
Class-Path: castor-0.9.5.jar dom4j.jar c3p0.jar commons-collections.ja
r odmg.jar xerces.jar xalan.jar commons-logging.jar hibernate2.jar eh
cache.jar cglib2.jar db2jcc.jar db2jcc_license_cu.jar j2ee.jar Absolu
teLayout.jar
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First: I guess this is a beginners question. Can someone move it?
Second: If you put a blank after the name of the class which contains a main-method, (or .class) in the manifest, it will fail.
(edited for typo)
[ March 25, 2004: Message edited by: Stefan Wagner ]
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This executable jar file was first created by using Webspher studio, and latter I have created using -jar option.
If this is a begginers question, then pls try solving it.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried explicitly specify full path of your "java".exe?
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post your manifest for us to see!!!
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Manifest-Version: 1.0
Main-Class: MainClassName
Here is the Manifest file.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your Main-classes name is really 'MainClassName'? (don't really believing).
Try

and post the 'test.tmp' to the forum.
It's essential to use the right starting-directory when creating the jar, using paths and jars.
Don't replace the output with something more readable when posting to the forum. This is polite and appropriate, when first asking your question, but since the answers don't help, we have to get into the details.
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are the details of the temp file.
META-INF/MANIFEST.MF
chatdev/ChatClient$1.class
chatdev/ChatClient$2.class
chatdev/ChatClient$CloseListener.class
chatdev/ChatClient$EnterListener.class
chatdev/ChatClient$SendListener.class
chatdev/ChatClient.class
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.
I assume your main-class is:
chatdev.ChatClient
am I true?
And you start it from

sucessfully?
Only to be sure:
Your Manifestfile contains:

And the jar is called 'chatdev.jar'?
so you try to run:

?
[ March 30, 2004: Message edited by: Stefan Wagner ]
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah your are right, but it does not work.
Using java -jar chatdev.jar it does not run. It throws exception.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems your jar is dependent on some external jar. In that case try this:
c:\>java -cp yourFile.jar;dependentFile.jar yourpack.yourMainClass
 
Vinod Chamoli
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It worked, thanks for your efforts.
But still one thing I dont understand, we have all jars in our classpath still it does not work, Can any one help me in solving this question.
Thanks
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sheesh, you guys... this ain't hard.
When you execute java with the "-jar" flag it ignores your environment CLASSPATH variable and the java "-cp" and "-classpath" flags.
Using the Class-Path manifest file entry is one way around this. The class path entries are filesystem based, relative to where the jar file is being executed from.
Another way is to unjar dependent jars and jar them back up into the application jar. Another way is to provide a simple executable (exe, bat, sh, whatever is suitable for any likely target environments) that does it the old-fashioned way. Another way is WebStart.
Lots of solutions. I personally like the "wrapper that calls java with the classname" as that provides a lot more flexibility in terms of setting the classpath, using or integrating the user's existing CLASSPATH, etc.
Dave
reply
    Bookmark Topic Watch Topic
  • New Topic