简体   繁体   English

java.lang.NoClassDefFoundError procrun

[英]java.lang.NoClassDefFoundError procrun

I tried to make my java application a windows service via procrun.我试图通过 procrun 使我的 Java 应用程序成为 Windows 服务。 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.如果您使用的是 Springboot 之类的技术,它有自己的启动器。 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".检查您的 jar 中的 Manifest 文件,您会在标签“Main-Class”下找到哪个是您的 jar 的真正入口点。 For instance, for Springboot you will find something like例如,对于 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/

Before launching YourApplication, Springboot must initialize everything for the framework, so the entry point of this jar would be the JarLauncher class.在启动 YourApplication 之前,Springboot 必须为框架初始化一切,所以这个 jar 的入口点将是 JarLauncher 类。 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.如果您还想处理 STOP 服务信号,请查看: Spring boot JAR as windows service。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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