gpt4 book ai didi

tomcat - FindClass 因 prunsrv 和 springboot 而失败?

转载 作者:行者123 更新时间:2023-11-28 22:49:03 29 4
gpt4 key购买 nike

我试图按照说明进行操作 here用于将我的 Spring Boot Web 服务作为 Windows 服务运行。如果我开始指向 org.springframework.boot.loader.JarLauncher,那么我的 Web 服务将启动并运行,但是当我尝试指向我添加的 Bootstrap 类时,我会收到“FindClass com/mycompany/Bootstrap failed”消息。所以 prunsrv 可以找到 SpringBoot 类,但找不到我的类。

有什么建议吗?使用 org.springframework.boot.loader.JarLauncher 似乎可以很好地启动 Windows 服务,但是我无法正常停止该服务,我必须在任务管理器中将其终止。

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Java]
"Jvm"="E:\\Java\\jre1.8.0_121_32\\bin\\client\\jvm.dll"
"Classpath"="E:\\Apache\\prunsvc\\myspringbootjar.jar"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Start]
"Class"="org.springframework.boot.loader.JarLauncher"
"Mode"="jvm"
"Method"="main"



[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\GMC_TLG_DEV\Parameters\Start]
"Class"="com.mycompany.Bootstrap"
"Mode"="jvm"
"Method"="start"

最佳答案

我能够解决这个问题,所以我发布了解决方案。

问题在于 Spring Boot 不再将应用程序类存储在正常的类路径中。 Spring Boot 有它自己的类加载器来加载应用程序类。为了将我的 com.mycompany.Bootstrap 类放在正确的位置,我将下面显示的 ANT 脚本添加到 Maven 构建中。这个脚本来自某处的帖子,但我不记得在哪里。

听起来 Radu 的解决方案也很合适。

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<target>
<zip destfile="${project.build.directory}/${project.build.finalName}.jar"
update="true" compress="store">
<fileset dir="${project.build.directory}/classes" >
<include name="com/mycompany/Bootstrap.class"/>
</fileset>
</zip>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

关于tomcat - FindClass 因 prunsrv 和 springboot 而失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46346547/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com