Reputation: 11
I am trying to run a Java program as a Windows service and my log file shows this error. I guess there is an error in providing the path but I am not able to figure it out.
2017-06-27 15:43:21 Commons Daemon procrun stderr initialized
java.lang.NoClassDefFoundError: ajavaservice/DemoService
Caused by:
java.lang.ClassNotFoundException: ajavaservice.DemoService
at java.net.URLClassLoader$1.run(Unknown Source)
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)
My batch file
set SERVICE_NAME=JavaService
set PR_INSTALL=C:\Eclipse\JavaService\prunsrv.exe
REM Service log configuration
set PR_LOGPREFIX=JavaService
set PR_LOGPATH=C:\Logs
set PR_STDOUTPUT=C:\Logs\stdout.txt
set PR_STDERROR=C:\Logs\stderr.txt
set PR_LOGLEVEL=Error
REM Path to java installation
set PR_JVM=C:\Program Files\Java\jre7\bin\client\jvm.dll
set PR_CLASSPATH=DemoService1.jar
REM Startup configuration
set PR_STARTUP=auto
set PR_STARTMODE=jvm
set PR_STARTCLASS=com.service.demoservice.DemoService
set PR_STARTMETHOD=start
REM Shutdown configuration
set PR_STOPMODE=jvm
set PR_STOPCLASS=com.service.demoservice.DemoService
set PR_STOPMETHOD=stop
REM JVM configuration
set PR_JVMMS=256
set PR_JVMMX=1024
set PR_JVMSS=4000
set PR_JVMOPTIONS=-Duser.language=DE;-Duser.region=de
REM Install service
prunsrv.exe //IS//JavaService
Upvotes: 1
Views: 697
Reputation: 719259
According to the stacktrace, the prunsrv.exe
is trying to load a Java class whose full name is ajavaservice.DemoService
, but the classloader cannot find it.
Now, I can't see where your BAT file is telling prunsrv.exe
to use that particular name. (Maybe you have "massaged" something? Maybe your com.service.demoservice.DemoService
class refers to it in some way?)
Either way, the solution is to ensure that the missing file is actually on the classpath. For a start, check that the the JAR file you are using contains a an entry for "/ajavaservice/DemoService.class". (Use "jar -t ..." to check it!)
UPDATE
Based on the comments, that's what the problem turned out to be. The classpath was incorrect. It apparently used an incorrect pathname for a JAR, which caused an old version to be used.
For other people with problems like this: if you get a ClassNotFoundException
check your JARs and your classpath carefully. You are missing something.
Upvotes: 1