简体   繁体   English

在cli中包含jar文件库

[英]include jar file libraries in cli

i am working on a project that uses a jnlp file. 我正在使用jnlp文件的项目中。 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. ant构建文件在build .jar中不包括那些jar文件。 how can i add those jars in the cli so that it doesn't give me "Exception in thread "main" java.lang.NoClassDefFoundError:" ? 我如何在cli中添加这些jar,以便它不会给我“线程“ 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? 我已经尝试过“ -cp file1.jar:file2.jar:etc.jar”,但是我在互联网上读到您无法将-cp与-jar一起使用。如何使它工作?

thanks in advance! 提前致谢!

You shouldn't embed jar files inside another jar file. 您不应该将jar文件嵌入另一个jar文件中。 That can only work if you use a special classloader. 仅当使用特殊的类加载器时,此方法才有效。 Use the -cp option when starting your app: 启动应用程序时,请使用-cp选项:

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 . 或按照此页面上的指示信息将jar文件的相对路径包括到myApp.jar的清单中,然后使用java -jar myApp.jar启动您的应用程序。

If you are on linux while compiling use 如果在编译时使用的是Linux

$ javac -cp myjar.jar Hello.java

And while running use, need to include current directory with dot 并且在运行使用时,需要在当前目录中包含点号

$ java -cp myjar.jar:. Hello

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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