tags:

views:

104

answers:

4

suppose in my application "MyClass", I want to use class A in jar1, and some part of class A depends on some class B in jar2. If I put both jar1 and jar2 on my classpath and run MyClass, it still complains that class B can not be found.

Could anybody tell me how to fix this problem?

Thanks a lot.

A: 

I have never encountered this being a problem, but have you tried putting jar2 before jar1 in the class path order? I think it's more likely that jar2 is simply not being included properly. Can you post the classpath setting?

Also, you may want to open up jar2 (it's just a zip file), and verify that the class you think is in there is in fact in there.

Chase Seibert
+2  A: 

The %CLASSPATH% environment variable is ignored when you use java command with -jar argument. Specify it using -classpath argument or its shorthand -cp. Alternatively you can also specify it in the class-path entry of the MANIFEST.MF file of the JAR file which you execute.

BalusC
A: 

I think that including jar2.jar in the jar1 MANIFEST.MF would probably work, provided they're in the same directory.

Kaleb Brasee
A: 

As other answers have mentioned providing the name of needed jar in the MANIFEST.MF
file of the jar that you invoke is one way to resolve your problem.

During jar file (the one you invoke first) creation you can specify the
manifest file which contains this detail so that it gets bundled with your jar.

The Java tutorial has a section on how to specify the Manifest file
during the jar creation.

If you are using ant as your build tool you can use
the ant task Manifest
to create a manifest file. You can use the Manifest file thus created in the
ant task that builds your jar.

Also check this link which provides more details about the Manifest file.

sateesh