简体   繁体   中英

Java Service Wrapper cannot find main class

Java Service Wrapper is the tools I need to run as a Windows service but came into a problem with java.lang.ClassNotFoundException

My default command line is: java -jar software.jar

I have update the wrapper.conf for running software.jar located in D:\\ and there was an error, the changes I have made:

# Java Classpath (include wrapper.jar)  Add class path elements as
#  needed starting from 1
wrapper.java.classpath.1=../software.jar
wrapper.java.classpath.2=../lib/wrapper.jar

and what should I put for this parameter? If I comment out, it would use Main class

wrapper.java.mainclass=software

As I declare "software" as the main class, I got the dread error:

wrapper  | Launching a JVM...
jvm 1    | java.lang.NoClassDefFoundError: org/xsocket/connection/IHandler
jvm 1    | Caused by: java.lang.ClassNotFoundException: org.xsocket.connection.I
Handler
jvm 1    |      at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
jvm 1    |      at java.security.AccessController.doPrivileged(Native Method)
jvm 1    |      at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
jvm 1    |      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
jvm 1    |      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

jvm 1    |      at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
jvm 1    | Could not find the main class: xSocketServer.  Program will exit.
wrapper  | JVM exited while loading the application.
jvm 1    | Exception in thread "main"
wrapper  | CTRL-C trapped.  Shutting down.
wrapper  | <-- Wrapper Stopped

My software.jar contains:

META-INF
org -- Eclipse setting
software.class
xsoftwareHandler.class
xSocket.jar

What I suggest is to store all libraries in your lib/ directory and then add the following information in your wrapper.conf file:

wrapper.java.classpath.1=../lib/*.jar

This way, the Java Service Wrapper will load all the *.jar file located in ../lib/ directory in the classpath, and you should not get this error again.

Of course, you can also define each JAR individually if you prefer:

wrapper.java.classpath.1=../lib/wrapper.jar
wrapper.java.classpath.2=../software.jar
wrapper.java.classpath.3=../lib/xSocket.jar
...

As you are using an executable jar to normally launch your application. You might want to try the WrapperJarApp helper class. It is designed to help with integration of executable jars without requiring you to dig into the Manifest file for the main class name. Take a look at this page for more information: http://wrapper.tanukisoftware.com/doc/english/integrate.html#method4

This has been available since version 3.3.3.

Cheers, Leif

The actual error does not seem to be with the Main class here. It seems to be with the "xSocket.jar" not being in the classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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