Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / March 2008

Tip: Looking for answers? Try searching our database.

Main-Class conflicts with the table of contents for a jar

Thread view: 
Thufir - 21 Mar 2008 08:25 GMT
I'm not sure what it's called, but the directory structure for this jar
looks wrong:

home/thufir/java/build/com/web_tomorrow/CPTest1.class

should be:

com/web_tomorrow/CPTest1.class

but I'm not sure how to correct it.  Is that a result of how the jar was
created or how javac was invoked?

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ ll
total 8
drwxr-xr-x 3 thufir thufir 4096 2008-03-21 00:16 com
-rw-r--r-- 1 thufir thufir 1411 2008-03-21 00:16 foo.jar
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ jar -tf foo.jar
META-INF/
META-INF/MANIFEST.MF
home/thufir/java/build/com/web_tomorrow/CPTest1.class
home/thufir/java/build/com/web_tomorrow/CPTest2.class
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ jar -xf foo.jar META-INF/MANIFEST.MF
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_03 (Sun Microsystems Inc.)
Main-Class: com.web_tomorrow.CPTest2.class

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$

It just seems to have "too much" information.

thanks,

Thufir
Thufir - 21 Mar 2008 08:44 GMT
> I'm not sure what it's called, but the directory structure for this jar
> looks wrong:

I believe that I've fixed that inconsistency but not fixed the general
problem.  When the class files are extracted from the jar they run as
expected.  When the Main-Class ?parameter? for the manifest is set to the
class file the resulting error is:

Exception in thread "main" java.lang.NoClassDefFoundError: com/
web_tomorrow/CPTest2/class

in more detail:

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ ll
total 4
-rw-r--r-- 1 thufir thufir 1319 2008-03-21 00:29 foo.jar
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ java -jar foo.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/
web_tomorrow/CPTest2/class
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ jar -tf foo.jar
META-INF/
META-INF/MANIFEST.MF
com/web_tomorrow/CPTest1.class
com/web_tomorrow/CPTest2.class
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ jar -xf foo.jar
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_03 (Sun Microsystems Inc.)
Main-Class: com.web_tomorrow.CPTest2.class

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ java com.web_tomorrow.CPTest2
Run CPTest2.main()
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$

(source code from http://www.kevinboone.com/classpath.html )

thanks,

Thufir
Roedy Green - 21 Mar 2008 08:58 GMT
>thufir@arrakis:~/java/build$
>thufir@arrakis:~/java/build$ ll

Perhaps you could post your jar file on the web somewhere.  I have no
clue what you are doing here.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Thufir - 21 Mar 2008 09:18 GMT
> Perhaps you could post your jar file on the web somewhere.  I have no
> clue what you are doing here.

http://hawat.thufir.googlepages.com/foo.jar

thanks,

Thufir
Thufir - 21 Mar 2008 09:25 GMT
It was just an error with the manifest.  I included the .class suffix in
the Main-Class :(

works now :)

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ java -jar foo.jar
Run CPTest2.main()
thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_03 (Sun Microsystems Inc.)
Main-Class: com.web_tomorrow.CPTest2

thufir@arrakis:~/java/build$
thufir@arrakis:~/java/build$

-Thufir
Roedy Green - 21 Mar 2008 11:55 GMT
>http://hawat.thufir.googlepages.com/foo.jar

I had a look in your jar.  I examined it with Jarlook:
see http://mindprod.com/products1.html#JARLOOK

META-INF/
META-INF/MANIFEST.MF
com/web_tomorrow/CPTest1.class
com/web_tomorrow/CPTest2.class

It looked like one of mine except you don't have what I would consider
a legit package name.  See http://mindprod.com/jgloss/package.html

I would have used a 3-part name like
com.web_tomorrow.cp

Which presumes you are the proud owner of web_tomorrow.com

Your manifest looks like this:
Manifest-Version: 1.0
Created-By: 1.6.0_03 (Sun Microsystems Inc.)
Main-Class: com.web_tomorrow.CPTest2.class

Here is what one of my manifests look like:

Manifest-Version: 1.0
Created-By: Jakarta Ant 1.7.0 (December 13 2006)
Main-Class: com.mindprod.bio.Bio

Name: com/mindprod/common11/Limiter.class
Last-Modified: Thu, 20 Mar 2008 15:58:29 PDT
Content-Location: E:\com\mindprod\common11\Limiter.class
...
with an entry for each class.

The problems include:
1. you appended .class where you should not.
2. You are missing entries for all the other classes.

See http://mindprod.com/jgloss/ant.html for how to build your manifest
properly or http://mindprod.com/jgloss/jarexe.html and
http://mindprod.com/jgloss/jar.html
for how to do it the old fashioned way.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Thufir - 21 Mar 2008 23:53 GMT
> The problems include:
> 1. you appended .class where you should not. 2. You are missing entries
[quoted text clipped - 4 lines]
> http://mindprod.com/jgloss/jar.html
> for how to do it the old fashioned way.

Thanks for checking it out :)

the java code, and the example, comes from:

http://www.kevinboone.com/classpath.html

It's working sufficiently that I didn't realize that entries for other
classes are missing, thanks for pointing that out.

-Thufir


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.