简体   繁体   English

清单中的类路径

[英]Classpath in Manifest

I have download a xSocket.jar which will be use as a classpath and compile myprogram.jar, both are in Java folder. 我已经下载了xSocket.jar并将其用作类路径并编译myprogram.jar,它们都在Java文件夹中。 Is adding a classpath in Manifest able to find xSocket.jar without the need to define a -cp in commandline? 在清单中添加类路径是否能够找到xSocket.jar,而无需在命令行中定义-cp

In my commandline D:\\> location, I tried running java -jar java\\myprogram.jar -n 0 在命令行D:\\>位置,我尝试运行java -jar java\\myprogram.jar -n 0

Exception in thread "main" java.lang.NoClassDefFoundError: org/xsocket/connectio
n/IBlockingConnection
        at myprogram.main(myprogram.java:114)
Caused by: java.lang.ClassNotFoundException: org.xsocket.connection.IBlockingCon
nection
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        ... 1 more

My Manifest in myprogram.jar: 我在myprogram.jar中的清单:

Manifest-Version: 1.0
Created-By: 1.6.0_22 (Sun Microsystems Inc.)
Main-Class: myprogram
Class-Path: xSocket

You need to specify the full jar file name ie with extension. 您需要指定完整的jar文件名,即扩展名。 Check here for more information. 在此处查看更多信息。

Class-Path: xSocket.jar

Is adding a classpath in Manifest able to find xSocket.jar without the need to define a -cp in commandline? 在清单中添加类路径是否能够找到xSocket.jar,而无需在命令行中定义-cp?

Yes, it's the way. 是的,就是这样。

You should change your class pass value in myprogram.jar to 您应该将myprogram.jar类通过值更改为

Class-Path: relatedPath/xSocket.jar

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

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