简体   繁体   中英

include jar file libraries in cli

i am working on a project that uses a jnlp file. in there there are resources specified like this:

[code]

<resources>
    <jar href="noterik-apu.jar" main="true" download="eager"/>
    <jar href="springfield-tools.jar" download="eager"/>
    <jar href="commons-httpclient-3.1.jar" />
    <jar href="commons-cli-1.2.jar" />
    <jar href="org.apache.commons.codec.jar" />
    <jar href="org.apache.commons.httpclient.jar" />
    <jar href="org.apache.commons.logging.jar" />
    <jar href="swing-worker-1.1.jar" />
    <jar href="log4j-1.2.16.jar" />
    <jar href="dom4j-1.6.1.jar" />
    <jar href="jaxen-1.1.1.jar" />
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
</resources>

[/code]

the ant build file does not include those jar files in the build .jar. how can i add those jars in the cli so that it doesn't give me "Exception in thread "main" java.lang.NoClassDefFoundError:" ? i have tried "-cp file1.jar:file2.jar:etc.jar" but i read on the internet that you can't use -cp with -jar.. how can i make it work?

thanks in advance!

You shouldn't embed jar files inside another jar file. That can only work if you use a special classloader. Use the -cp option when starting your app:

java -cp lib\*:.\myApp.jar com.foo.bar.MyApp

Or include the relative paths of the jar files into the manifest of myApp.jar by following the instructions on this page , and start your app with java -jar myApp.jar .

If you are on linux while compiling use

$ javac -cp myjar.jar Hello.java

And while running use, need to include current directory with dot

$ java -cp myjar.jar:. Hello

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM