【问题标题】:FindClass failed with prunsrv & springboot?FindClass 因 prunsrv 和 springboot 而失败?
【发布时间】:2017-09-21 14:26:20
【问题描述】:

我试图按照说明here 将我的 Spring Boot Web 服务作为 Windows 服务运行。如果我将 start 指向 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"

【问题讨论】:

    标签: tomcat spring-boot prunsrv


    【解决方案1】:

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

    问题在于 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>
    

    【讨论】:

      【解决方案2】:

      我知道你的帖子已经很久了,但我今天遇到了同样的问题。可能与 Spring Boot 1.4.0 以后 JAR 文件的打包方式有所改变有关。

      这里的说明在我的情况下有效: https://github.com/spring-projects/spring-boot/issues/6792#issuecomment-243564648

      【讨论】:

      • 你是对的,看我的回答。然而,我以不同的方式解决了这个问题。你的解决方案看起来也不错,不知道你为什么被否决
      猜你喜欢
      • 2017-05-05
      • 2022-01-05
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 2012-11-18
      相关资源
      最近更新 更多