FindClass failed with prunsrv & springboot?

1.5k Views Asked by At

I was trying to following the instructions here for running my Spring Boot web service as a windows service. If i point start to org.springframework.boot.loader.JarLauncher then my web service starts & works, but when I try to point to the Bootstrap class I added then I get a "FindClass com/mycompany/Bootstrap failed" message. So prunsrv can find the SpringBoot classes but not my classes.

Any suggestions? Using org.springframework.boot.loader.JarLauncher seems to work fine for starting the windows service but then I can't stop the service normally, I have to kill it in task manager.

[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"
2

There are 2 best solutions below

0
On BEST ANSWER

I was able to figure this out, so im posting the solution.

The issue is that Spring Boot no longer stores application classes on the normal class path. Spring boot has its own class loader that loads application classes. In order to put my com.mycompany.Bootstrap class in the correct location, I added the ANT script shown below to the Maven build. This script came from a post somewhere, but I do not recall where.

Sounds like Radu's solution is appropriate also.

        <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>
1
On

I know it's a long time since your post but I ran into the same issue today. It might be related to the changed packaging of JAR files in Spring Boot since 1.4.0.

The instructions here worked in my case: https://github.com/spring-projects/spring-boot/issues/6792#issuecomment-243564648