How to set classpath for jar in jar

mahome
mahome used Ask the Experts™
on
Hello Experts,

I've created a jar with the content as you see below. A main class and required jars under lib folder.
In the manifest I included the required jars in the classpath.

But when I want to start application with: java -jar myapp.jar I'm getting the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException

So it seems that jaxrpc.jar is not found and s.th. with the classpath is incorrect.
Please help me to correct my classpath.
jar content:
de/myapp/MyMain.class
META-INF/MANIFEST.MF
lib/jaxrpc.jar
lib/axis.jar
...

manifest:
Manifest-Version: 1.2
Main-Class: de.myapp.MyMain
Class-Path: lib/axis.jar lib/jaxrpc.jar ...
Created-By: 1.5.0_15 (Sun Microsystems Inc.)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you can't have jar inside a jar, the lib folder you mentioned in the manifest, it will look for the in the system not with in the jar. if this is how you want to run, you may want to write your own classloader!
Top Expert 2016
Commented:
You can't nest jars unless you use 'Fat Jar' techniques. It will expect jars in the same directory per your usage
Top Expert 2016

Commented:
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Mick BarryJava Developer
Top Expert 2010

Commented:
take the jars out of the jar and instead put them in a lib directory with your application jar.
That should work (and makes it easy to upgrade the external jars without having to build a new jar)

Author

Commented:
Thanks for your fast help.
Top Expert 2016

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial