Spring Boot maven plugin cant find main class, Could not exec java

Spring :

I have a multi module maven spring-booot maven project. One of the child modules is a stub(a spring boot app) that I want to start and then stop during integration tests of myRealApp.

Parent Pom
|   
|----myRealApp module(spring boot app)
|----stub-of-some-remote-rest-api module(This is also a spring-boot app)

This is how the pom file looks like in the module myRealApp. Which also has all the integration tests. Its trying to start the stub module during before integration-tests phase. But I get the error when I run maven goal in the child module directory:

 mvn integration-tests -X

Error: Could not find or load main class io.swagger.MyStub

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.8.RELEASE:run (start-boot) on project: Could not exec java

I can see in debug mode that that the working directory is set correctly.

Pom of myRealApp:

         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>${spring.boot.mainclass}</mainClass>
            </configuration>
            <executions>
                <execution>
                    <configuration>
                        <workingDirectory>${project.parent.basedir}/module-of-my-stub/src/main/java</workingDirectory>
                        <mainClass>io.swagger.MyStub</mainClass>
                    </configuration>
                    <id>start-boot</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-boot</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>stop</goal>
                    </goals>
                </execution>
                <execution>
                    <goals>
                        <goal>build-info</goal>
                    </goals>
                </execution>
            </executions>

        </plugin>

Maybe I am not allowed to set workingDirectory in individual executions, or give reference to an other module?

The stub is there acting like a remote rest service which my application is depending on, which I used during development since the actual remote service's test environment was not reliable and was down half of the time. So decided to also use it in Integration tests too.

df778899 :

To consolidate some of the comments against the question, these basically followed the advice in this other answer.

The key was setting the classesDirectory against the spring-boot-maven-plugin:run goal to point to the target\classes directory under the other project.

  <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <mainClass>${spring.boot.mainclass}</mainClass>
        </configuration>
        <executions>
            <execution>
                <id>start-stub</id>
                <configuration>
                    <arguments>
                        <argument>--server.port=8090</argument>
                    </arguments>
                    <mainClass>io.swagger.Stub</mainClass>
                    <classesDirectory>../my-stub/target/classes</classesDirectory>
                </configuration>
                <goals>
                    <goal>start</goal>
                </goals>
                <phase>pre-integration-test</phase>
            </execution>

            <execution>
                <goals>
                    <goal>build-info</goal>
                </goals>
            </execution>
        </executions>
  </plugin>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=82842&siteId=1