简体   繁体   中英

java.lang.NoClassDefFoundError procrun

I tried to make my java application a windows service via procrun. but when I start the service I get the following error:

2019-06-07 17:19:25 Commons Daemon procrun stderr initialized
java.lang.NoClassDefFoundError: SaveData 
Caused by: java.lang.ClassNotFoundException: SaveData 
    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)
Exception in thread "main" 

2019-06-07 17:19:25] [error] [25304] FindClass SaveData  failed
[2019-06-07 17:19:25] [error] [21836] Failed to start Java
[2019-06-07 17:19:25] [error] [21836] ServiceStart returned 4
[2019-06-07 17:19:25] [info]  [ 8688] Run service finished.
[2019-06-07 17:19:25] [info]  [ 8688] Commons Daemon procrun finished

can someone help me? thank you

file batch for the installation

set SERVICE_NAME=TestService
set PR_INSTALL=C:\Users\sergi\Desktop\SaveData\prunsrv.exe
REM Service log configuration 
set PR_LOGPREFIX=%SERVICE_NAME% 
set PR_LOGPATH=%~dp0%
set PR_STDOUTPUT=%~dp0%\stdout.txt 
set PR_STDERROR=%~dp0%\stderr.txt 
set PR_LOGLEVEL=Error   
REM path to java installation
set PR_JVM=C:\Program Files\Java\jre1.8.0_191\bin\server\jvm.dll
set PR_CLASSPATH=C:\Users\sergi\Desktop\SaveData\testservice.jar
REM Startup configuration
set PR_STARTUP=auto
set PR_STARTMODE=jvm
set PR_STARTCLASS=SaveData 
set PR_STARTMETHOD=main
REM Shutdown configuration 
set PR_STOPMODE=jvm 
set PR_STOPCLASS=SaveData
set PR_STOPMETHOD=main
REM JVM configuration 
set PR_JVMMS=256 
set PR_JVMMX=1024 
set PR_JVMSS=4000 
REM JVM options 
set prunsrv_port=8080 
set prunsrv_server=localhost
REM Install service 
C:\Users\sergi\Desktop\SaveData\prunsrv.exe //IS//%SERVICE_NAME%

If you are using a technology like Springboot, it has its own launcher. Check out your Manifest file inside your jar and you will find which is the real entry point for your jar under the label "Main-Class". For instance, for Springboot you will find something like

Manifest-Version: 1.0
Implementation-Version: 1.1.0-SNAPSHOT
Spring-Boot-Version: 2.1.0.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.yourcompany.application.YourApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/

Before launching YourApplication, Springboot must initialize everything for the framework, so the entry point of this jar would be the JarLauncher class. So, in this case, you should change your settings to

set PR_STARTCLASS=org.springframework.boot.loader.JarLauncher

This should be enough to start your service (this is your question). If you also want to handle the STOP service signal, then check this out: Spring boot JAR as windows service.

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