当 MANIFEST.MF 中列出该类时,为什么我的 jar 会生成 NoClassDefFoundError?
我已在以下文件夹 usr/local/bin/niidle.jar
中创建了 jar,我的 MANIFEST.MF
文件如下:
Manifest-Version: 1.0 Main-Class: com.ensarm.niidle.web.scraper.NiidleScrapeManager Class-Path: hector-0.6.0-17.jar
我验证了文件 hector -0.6.0-17.jar
也存在于该文件夹中:
<块引用>/Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar
我不想在 MANIFEST.MF 文件中给出完整的类路径名称,因为我必须运行这个 jar在另一台机器上。所以我在 MANIFEST.MF 文件中只给出了 jar 文件名 Class-Path=hector-0.6.0-17.jar
。
尽管在 MANIFEST.MF 文件中提到了类路径,但当我使用命令运行此命令时:
<块引用>java -jar /usr/local/bin/niidle.jar 参数...
它显示错误消息:
--Exception in thread "main" java.lang.NoClassDefFoundError: me/prettyprint/hector/api/Serializer at com.ensarm.niidle.web.scraper.NiidleScrapeManager.main(NiidleScrapeManager.java:21) Caused by: java.lang.ClassNotFoundException: me.prettyprint.hector.api.Serializer at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 1 more
请给我一个解决此错误消息的方法。
I have created jar in the following folder usr/local/bin/niidle.jar
and my MANIFEST.MF
file is as follows:
Manifest-Version: 1.0 Main-Class: com.ensarm.niidle.web.scraper.NiidleScrapeManager Class-Path: hector-0.6.0-17.jar
I verified that the file hector-0.6.0-17.jar
is also present in the folder:
/Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar
I don't want to give full class-path name in MANIFEST.MF
file, because I have to run this jar on another machine. So I gave only jar file name Class-Path=hector-0.6.0-17.jar
in MANIFEST.MF file.
In spite of mentioning the Class-Path in MANIFEST.MF file, when I run this using command:
java -jar /usr/local/bin/niidle.jar arguments...
It is showing the error message:
--Exception in thread "main" java.lang.NoClassDefFoundError: me/prettyprint/hector/api/Serializer at com.ensarm.niidle.web.scraper.NiidleScrapeManager.main(NiidleScrapeManager.java:21) Caused by: java.lang.ClassNotFoundException: me.prettyprint.hector.api.Serializer at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:252) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) ... 1 more
Please give me a solution for this error message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Class-Path 是 jar 文件所在目录的相对路径或绝对路径。
因此,对于您的情况,您必须将 hector-0.6.0-17.jar 复制到 /usr/local/bin
Class-Path is relative or absolute to the directory where your jar file is located.
so for your case you have to hector-0.6.0-17.jar to /usr/local/bin