jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Jar file" Watch "Jar file" New topic
Author

Jar file

David Khoi Pham
Greenhorn

Joined: Jun 20, 2007
Posts: 15
Hello!

I packaged all my files into runme.jar as per my requirements. I made it with a manifest file which looks like this:

Manifest-Version: 1.0
Main-Class: suncertify.client.Main
Created-By: 1.2 (Sun Microsystems Inc.)

But, when I run my jar (C:\SCJD\URLyBird>java -jar runme.jar alone), it says

Exception in thread "main" java.lang.NoClassDefFoundError: suncertify/client/Main

My classpath environment variable is:
C:\scjd\urlybird\code

In the code directory, the folder suncertify exists and so on.

To be honest, I knew something about the classpath was going to pop out at me but I'm not sure how to fix it. Any guidance?

Thanks,
David Pham

[ August 22, 2007: Message edited by: David Khoi Pham ]
[ August 22, 2007: Message edited by: David Khoi Pham ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42909
    
  68
I'm a bit confused because you mention trying to run a jar file, but the command you posted does not reference that jar file. I would expect the command to be something like "java -jar runme.jar".
David Khoi Pham
Greenhorn

Joined: Jun 20, 2007
Posts: 15
Oops sorry! I edited the post.
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
Perhaps it would help if you list files in your jar:


and you should see:
suncertify/client/Main.class

You are mentioning 'code' directory, which suggest, that you perhaps packed your jar file from sources and not from classes. (in my assignment, I should put sources in 'code' dir)
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
One more thing: You shouldn't need any classpath settings besides standard java libraries. I also suggest before submission to run it on different pc without any sources/classes,.. just the jar file.
David Khoi Pham
Greenhorn

Joined: Jun 20, 2007
Posts: 15
When I ran the command to list out files, I got this:


[ August 23, 2007: Message edited by: David Khoi Pham ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42909
    
  68
920 Wed Aug 22 19:02:12 CDT 2007 code/suncertify/client/Main.class


There's your problem: all clases are inside of the code directory. If the package name is "suncertify.client", then the suncertify directory must be at the top level of the jar file, not inside some other directory.
David Khoi Pham
Greenhorn

Joined: Jun 20, 2007
Posts: 15
Thank you!

I fixed the problem!

Is it okay if I have code, docs, and suncertify (this is the extra) directories?
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
I think you don't need to put all docs, etc. in runme.jar

take a look here: http://1024labs.org/john.stone/scjd_jar_example.png
(It is from K&B book, I hope it is ok to post this small piece of information)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar file