Code Comments
Programming Forum and web based access to our favorite programming groups.Is it possible to run a jar file that is contained within another jar file? I have tried and can't seem to get it to work. I have the following manifest in test.jar : Manifest-Version: 1.0 Main-Class: com.efinery.RunTest This runs fine using "java -jar test.jar" from the command line. However, when I place it inside a jar called mainapp.jar and have it's manifest reference test.jar in the Classpath as follows : Manifest-Version: 1.0 Main-Class: com.efinery.RunTest Classpath: runme.jar When I try to run "java -jar mainapp.jar" I get a java.lang.NoClassDefFoundError. Can anybody tell me what I am doing wrong? Any help would be much appreciated.
Post Follow-up to this messageApologies, I made a typo. The mainfest for mainapp.jar is as follows : Manifest-Version: 1.0 Main-Class: com.efinery.RunTest Classpath: test.jar
Post Follow-up to this messageefinery wrote: > This runs fine using "java -jar test.jar" from the command line. However, > when I place it inside a jar called mainapp.jar and have it's manifest > reference test.jar in the Classpath as follows : > > Manifest-Version: 1.0 > Main-Class: com.efinery.RunTest > Classpath: runme.jar > > When I try to run "java -jar mainapp.jar" I get a > java.lang.NoClassDefFoundError. Can anybody tell me what I am doing wrong? Sure. You're reading the documentation wrong. What you are attempting is not supposed to work. The Class-Path manifest attribute lists other jar files that will be in the same directory as the one you're running, NOT other jar files that are recursively packaged inside the one you're running. There is no default classloader that's capable of loading classes from a nested jar file. You could write your own, though, by using getResource to get a URL for the nested JAR file, and then URLClassLoader to load classes from it. -- www.designacourse.com The Easiest Way to Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
Post Follow-up to this messageefinery <hugh@efinery.com> wrote: > Is it possible to run a jar file that is contained within another jar file?[/color ] AFAIK, no. But you can use the Class-Path: header to reference jar files in the same directory. So if you place test.jar and mainapp.jar in the same directory, and the manifest of mainapp.jar contains the line below, it'll work: Class-Path: test.jar -- Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.