开发者

problem with setting the class path in manifest.mf within jar file

开发者 https://www.devze.com 2023-02-04 07:15 出处:网络
I have created the jar file,and I run it using command:- java -jar /usr/local/bin/niidle.jar arguments...

I have created the jar file,and I run it using command:-

java -jar /usr/local/bin/niidle.jar arguments...

then I got this error---- 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 removed this error by mentioning the full class path name, Class-Path=/Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar in MANIFEST.MF. And now when I run it by using command:-

java -cp /Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar -jar /usr/local/bin/niidle.jar arguments...

its working properly.

But I want to mention only jar file name "hector-0.6.0-17.jar" in Class-Path in MANIFEST.MF.If I give full class path,then it will not work on others machine.And I have to run this jar on others machine. And when I mention only jar file name "hector-0.6.0-17.jar",and I run it using command:-

java -cp /Projects/EnwelibDatedOct13/Niidle/lib/hector-0.6.0-17.jar -jar /usr/local/bin/niidle.jar arguments... it is showing me same 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.prettypri开发者_开发知识库nt.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 dont want to mention full class path name in MANIFEST.MF,so please tell me solution for this, or how to set only jar file name "hector-0.6.0-17.jar" to Class-Path in MANIFEST.MF in the jar.


You have to write the relative class path in your manifest file. For example if your application has lib directory where all third party jars are held just add the following line to your manifest file:

Class-Path: lib/hector-0.6.0-17.jar

now this java -jar bin/niidle.jar arguments... should work if your are running it from /usr/local/

I'd recommend you to put all your jar files in one directory, e.g. lib. It is easier to maintain. Bin directory should contain scripts.

0

精彩评论

暂无评论...
验证码 换一张
取 消