File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using Jar" Watch "Using Jar" New topic
Author

Using Jar

Lee Sunter
Greenhorn

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

SCJD
> Code
> client
client code
URLyBirdStartUp
> 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 manifest.mf .

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 manifest.mf 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
@lee

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

@daniel

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,

jan
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11490
    
  95

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
 
Don't get me started about those stupid light bulbs.
 
subject: Using Jar