aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Creating the .jar file 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 "Creating the .jar file" Watch "Creating the .jar file" New topic
Author

Creating the .jar file

Charlie Goth
Ranch Hand

Joined: Feb 26, 2004
Posts: 60
is driving me mad.
Any help would be appreciated, I've looked at the trail at java.sun.com but I'm getting a java.lang.NoClassDefFoundError when I try to execute the file.

Files:
code <dir>
db-2x2.db
MANIFEST.MF

I'm typing:
"jar cvf runme.jar code db-2x2.db"
"jar umf manifest.mf runme.jar"
"java -jar runme.jar" - which gives me "Exception in thread "main" java.lang.NoClassDefFoundError: code/both/RunApp (wrong name: both/RunApp)

Manifest.mf:
"Main-Class: code.both.RunApp
"

The RunApp file is definately in the jar and definately has a public static void main(String[] args) method.

Any ideas?


SCJP (77%)
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
You may read about it here:

http://www.cs.princeton.edu/introcs/85application/jar/jar.html

But anyaway, check out your manifest file. Say, copy contents from the link above and correct the file name.

1. Create manifest file
-------
Manifest.mf:

Manifest-Version: 1.0
Main-Class: your package.somepath.Start

-------

2. Make executable jar

$ jar cmf Manifest.mf runme.jar suncertify

// suncertify is the root directory for your packages


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Charlie Goth
Ranch Hand

Joined: Feb 26, 2004
Posts: 60
Not having much luck

What should go in the Main-Class section of the manifest?
The main class is in code/both/ BUT the package is just both.
I get slightly different output depending on what I specify as the Main-Class:
With code.both.RunApp I get a NoClassDefFoundError: code/both/RunApp (Wrong name: both/RunApp)with a stacktrace.

With both.RunApp I just get NoClassDefFoundError: both/RunApp

I've run what you suggested on a little app (1 class) and it works fine, so I think it's the code directory that is screwing it up (with a little help from me).
Vishwa Kumba
Ranch Hand

Joined: Aug 27, 2003
Posts: 1066
Charlie,
There are 2 jar files for the assignment.
1. runme.jar file - this is supposed to contain only the class files.
As Denis mentioned, this is supposed to contain only, suncertify directory as the root package.
2. The complete jar file consisting the runme.jar file, the code directory(source code), version.txt, db2x2.db file, docs directory etc. This has a different name, something like SCJD_YourPrometricID.jar. Sorry, I cannot remember what exactly it is at this moment.May be the others can help you on this.After completion of the assignment, we upload this jar file for evaluation.

The examiner is expected to unjar the second jar file into a directory and then use runme.jar file to run/test our application.

runme.jar is expected to contain a maninfest file with the
Main-Class: entry. In ur case, I guess it could be

Main-Class: both.RunApp.

RunApp is the name of the class that has the main method and
both is the package in which RunApp class is defined.

Remember code directory contains the source files and is not used to run
your application.

if suncertify is not your root package(it should be for the assignment!), then create the runme.jar file with whatever root package/directory you have.

example:

jar cmf Manifest.mf runme.jar both

(if both is ur root package containing the other subpackages and classes)

You can test your application with the runme.jar file. Ignore the second jar file for the time being, you can do it later when you are ready to upload the assignment.

BTW, your package names are different, which assignment are you working on?
Charlie Goth
Ranch Hand

Joined: Feb 26, 2004
Posts: 60
I did misread some stuff, so I'll try again.
I didn't have a base directory, I'm getting Eclipse to move things around now though.

Thanks
Charlie
Charlie Goth
Ranch Hand

Joined: Feb 26, 2004
Posts: 60

Thanks again

Charlie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating the .jar file