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

Using Jar

 
Lee Sunter
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic