File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using Jar" Watch "Using Jar" New topic

Using Jar

Lee Sunter

Joined: Mar 21, 2005
Posts: 29
I have the file structure

> Code
> client
client code
> server
> Doc

I can use the jar command to run when there is no 'code' directory? but not when there is a code directory in the structure.

I run D:\SCJD>jar cvfm URLyBird.jar .

This puts in all the files and when I look at the jar I see that the URLyBirdStartUp.class is in the directory structure /code/client/

but when I try to run
D:\SCJD>java -cp .\URLyBird.jar client.URLyBirdStartUp alone
it thorws a
Exception in thread "main" java.lang.NoClassDefFoundError: client/URLyBirdStartUp

Anyone got any ideas as I have tried different combinations?
My contains Main-Class: client.URLyBirdStartUp

Thanks in advance
Daniel Dalton
Ranch Hand

Joined: Mar 20, 2005
Posts: 146
Hi Lee - I could be completely wrong here, but my understanding of the requirements (at least those for mine) is that first you have to create an executable jar file (called runme.jar in my case). Having done that, you have to package everything up - source code, choices.txt etc AND runme.jar into a second jar file. The assessor then unjars THIS file and is only then able to run the program.

You appear to be trying to run the executable from a jar which contains a Doc directory rather than just your classes...
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456

java -jar your.jar ... had the same issue last night ;-)


i seem to be in the same stage of progress then you, just thinking about the requirements for the submission. my interpretation is the same then yours...

can anyone confirm the delivery of two jars, one packing the other?

thanks a lot,

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11778

Hi Lee, Daniel, and Jan,

Yes, there are two JAR files; one inside the other.

Get the executable jar file working first - it will not have the directory prefix '/code/'.

Once you have the executable jar file working, then you can package the executable jar, the doc directory, the source directory, and the additional files into another jar file (which will not be executable).

Make sure you read your instructions carefully to make sure you get packaging perfect. There have been cases of candidates being failed for doing something silly like having source files in a 'source' directory instead of a 'src' directory. You must follow what is written in your instructions to the letter.

Regards, Andrew

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: Using Jar
It's not a secret anymore!