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 / June 2005

Tip: Looking for answers? Try searching our database.

jar problems

Thread view: 
arvindsd@yahoo.com - 27 May 2005 11:11 GMT
Hi all,

My application is something like this:

I have two files:
c:\test\a\b\JarTest.class
c:\test\c\d\JarMan.class

The java code is as follows:

JarTest.java
------------
package a.b;

import c.d.JarMan;

public class JarTest{
    public static void main(String asd[]){
        JarMan jm    =    new JarMan();
        jm.testFunc();
    }
}

JarMan.java
------------

package c.d;

public class JarMan{
    private int a;

    public void testFunc(){
        System.out.println("print:: "+this.a);
    }
}

Now I created a jar file out of c/d/JarMan.class with the correct
directory structure called jarman.jar.

And created an exceutable jar file out of a/b/JarTest.class called
jartest.jar.

The manifest file in jartest.jar looks like this:

Manifest-Version: 1.0
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: a.b.JarTest

Now from within the c:\test folder I try to execute jartest.jar and
this is what happens:

C:\test>java -classpath c:\test\jarman.jar; -jar jartest.jar
Exception in thread "main" java.lang.NoClassDefFoundError: c/d/JarMan
       at a.b.JarTest.main(JarTest.java:7)

Strange isnt it?

Now when I extract the contents of jartest.jar and try it works:
C:\test>java -classpath c:\test\jarman.jar; a/b/JarTest
print:: 0

My head is spinning with this problem :-(

Help me out!!!
Thanks in advance.

regards,
ASD
Fahd Shariff - 27 May 2005 15:38 GMT
I don't know why
C:\test>java -classpath c:\test\jarman.jar; a/b/JarTest  is working

Isn't the name of the main class a.b.JarTest?

I think it may be due to your classpath because the error indicates
that it can't find c/d/JarMan

Perhaps you should try:

C:\test>java -classpath .;c:\test\jarman.jar -jar jartest.jar

Signature

Fahd Shariff
"Let the code do the talking... "

Fahd Shariff - 27 May 2005 16:07 GMT
Ignore my previous email. I got it wrong.

You cannot have both -classpath and -jar as path of the java command.
"When you use -jar, the JAR file is the source of all user classes, and
other user class path settings are ignored." This is why it cant find
the JarMan class because the jarman jar file is being ignored.

What you need to do is add the Class-Path attribute to the manifest:

Class-Path: jarman.jar

Signature

Fahd Shariff
"Let the code do the talking... "

arvindsd@yahoo.com - 01 Jun 2005 08:44 GMT
Hi Fahd,

Thanks for the input.
Now my manifest file looks like below:

Manifest-Version: 1.0
Created-By: 1.4.2_04 (Sun Microsystems Inc.)
Main-Class: a.b.JarTest
Class-Path: c:\test\jarman.jar

But I still get some error:
C:\test>java -jar a.jar
Failed to load Main-Class manifest attribute from
a.jar

regards,
ASD


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.