2

我试图通过 procrun 使我的 java 应用程序成为 Windows 服务。但是当我启动服务时,出现以下错误:

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

有人能帮我吗?谢谢你

安装文件批处理

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%
4

1 回答 1

1

如果你使用像 Springboot 这样的技术,它有自己的启动器。查看 jar 中的 Manifest 文件,您会发现在标签“Main-Class”下哪个是 jar 的真正入口点。例如,对于 Springboot,您会发现类似

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/

在启动 YourApplication 之前,Springboot 必须初始化框架的所有内容,因此这个 jar 的入口点将是 JarLauncher 类。因此,在这种情况下,您应该将设置更改为

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

这应该足以启动您的服务(这是您的问题)。如果您还想处理 STOP 服务信号,请查看:Spring boot JAR as windows service。

于 2020-04-27T11:10:07.763 回答