Proyb2
Proyb2

Reputation: 993

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. Is adding a classpath in Manifest able to find xSocket.jar without the need to define a -cp in commandline?

In my commandline D:\> location, I tried running 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:

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

Upvotes: 1

Views: 1413

Answers (2)

Roman
Roman

Reputation: 66216

Is adding a classpath in Manifest able to find xSocket.jar without the need to define a -cp in commandline?

Yes, it's the way.

You should change your class pass value in myprogram.jar to

Class-Path: relatedPath/xSocket.jar

Upvotes: 1

Faisal Feroz
Faisal Feroz

Reputation: 12785

You need to specify the full jar file name i.e. with extension. Check here for more information.

Class-Path: xSocket.jar

Upvotes: 2

Related Questions