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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "help with jar utility" Watch "help with jar utility" New topic
Author

help with jar utility

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
my application main class directory is as follow:
suncertify/bin/Runme.class

and suncertify directory is in a folder called dev
I am try to jar succertify, and updating the manifest so that the application can run using the command

java -jar runme.jar

I am using the following command to jar my files:
C:\dev>jar cf class-name suncertify/bin/Runme.class runme.jar suncertify*

it produces the jar file, however when I run it I get this error:
C:\dev>java -jar runme.jar
Failed to load Main-Class manifest attribute from
runme.jar

Am I missing a flag or something?
I am running JDK 1.4.2_4

can someone help please.
Like what you can tell, I am wrapping this application up, and I should take the test exam early next week.


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
http://www.cs.princeton.edu/introcs/85application/jar/jar.html


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Hanna,

As shown in the link provided by Denis (good link Denis, it is now in our Reading Materials FAQ), you must create a manifest which describes which class is the class to run.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Denise and Andrew:
Thanks for the helpful link. I couldn't get it to work though.
I created the manifes.mf file. which contains

Manifest-Version: 1.0
Main-Class: Runme

my directory structure is:
suncertify>bin //has all classes
suncertify>code //has the source files
suncertify>manifest.mf // the manifest file

C:\dev>jar cmf suncertify/manifest.mf runme.jar suncertify*

when I run it I got class not found error.
C:\dev>java -jar runme.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Runme

Runme.class is in the default package:
suncertify/code/Runme.java
suncertify/bin/Runme.class

It works fine only if I generate the jar file from the directory where the Runme.class is located.

any clue what is going on here.
thanks
[ June 08, 2004: Message edited by: Hanna Habashy ]
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72

I created the manifes.mf file. which contains
Manifest-Version: 1.0
Main-Class: Runme

my directory structure is:
suncertify>bin //has all classes
suncertify>code //has the source files
suncertify>manifest.mf // the manifest file

C:\dev>jar cmf suncertify/manifest.mf runme.jar suncertify*

when I run it I got class not found error.
C:\dev>java -jar runme.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Runme

Runme.class is in the default package:
suncertify/code/Runme.java
suncertify/bin/Runme.class


Hanna, first of all, do you have to include source files into executable jar? I dont know about B&S, but in URLyBird it is required to include only code.
As to packaging, I will simply explain how I did and you'll see whats the problem:
1. I have such file structure:
suncertify
|____ db___ files
|____client___files / contains file Start.class
|____server___ files
2. In root folder (one which contains suncertify) i placed mf.mf:

Manifest-Version: 1.0
Main-Class: suncertify.client.Start // <--- full path

3. Then I type:

$ jar cmf mf.mf runme.jar suncertify

4. Now java -jar runme.jar must work.

[ June 09, 2004: Message edited by: Denis Spirin ]
[ June 09, 2004: Message edited by: Denis Spirin ]
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi Denis:
My instruction states:

When you submit your assignment, each part (client and server) must be executable using a command of this exact form:

java -jar <path_and_filename> [<mode>]

I understand form that I must have an executable jar.
My instruction doesn't state anything about .class files, but how can I execute the jar without calss files? Also, how about stubs , I genereate the stubs using rmic compiler, and I leave in the bin directory.

I tried to add the full path of the main class file, and it didn't work.
I tried to add the class name in the manifest using:
Name: suncertify.bin.Runme.class
and still didn't work.
It works only if I generate the jar file while I am in the bin directory, I don't know what else to do.
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
I understand form that I must have an executable jar.
My instruction doesn't state anything about .class files, but how can I execute the jar without calss files? Also, how about stubs , I genereate the stubs using rmic compiler, and I leave in the bin directory.

Your jar must include only .class files (not source files) and stub(s)/skeleton(s).

I tried to add the full path of the main class file, and it didn't work.
I tried to add the class name in the manifest using:
Name: suncertify.bin.Runme.class
and still didn't work.
It works only if I generate the jar file while I am in the bin directory, I don't know what else to do.

Check out all your steps again. Name must not include ".class", it should look like "suncertify.bin.Runme".
Are your files in corresponding packages (suncertify.bin etc)? Check if mf file is in plain text format.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
Denis:
It is all my fault. I didn't understand the requirent corrctly. It states that the deliverabal is a jar file containting the excutable jar file. All the time I thought it would be one single jar contains all the project elements.
I have been working on my project constantly for the last week, my brain needs some oil.
Thank again for all your time.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: help with jar utility
 
Similar Threads
Jar file
manifest.mf and runme.jar
UrlyBird: Codebase file location
How to create/run client.jar
URLyBird: runme.jar