Reputation: 23
I am trying execute a java class which accesses a method in a jar file.My package structure is com.xmlpost.XmlPostInit.java and it resides under the directory:
D:\Workspace\Test\bin
I am using the command below. Note, cs.jar
contains the class com.xmlpost.XmlPostInit
D:\Workspace\Test\bin>java -classpath D:\FatWire\JSK\7.6.0\App_Server\apache-tomcat-6.0.18\webapps\cs\WEB-INF\lib\cs.jar com.xmlpost.XmlPostInit
.. which gives me following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/xmlpost/XmlPostInit
Caused by: java.lang.ClassNotFoundException: com.xmlpost.XmlPostInit
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.xmlpost.XmlPostInit. Program will exit.
Upvotes: 1
Views: 611
Reputation: 13468
You have to add your bin directory to the classpath too, as the JVM needs to look inside it to find your class. As you are running inside it, you can refer localy it with ".":
D:\Workspace\Test\bin>java -classpath .;D:\FatWire\JSK\7.6.0\App_Server\apache-tomcat-6.0.18\webapps\cs\WEB-INF\lib\cs.jar com.xmlpost.XmlPostInit
Upvotes: 1