简体   繁体   中英

Launch multi module maven/spring project

i'm new to maven and i've finished my app i can lauch it from eclipse and there is no error when i run mvn clean package but i tried to lauch it with mvn spring-boot:run and i 've this error :

java.lang.ClassNotFoundException: com.o2xp.ats.utils.App
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:522)
    at java.lang.Thread.run(Thread.java:748)

but i've specified the path of my main class in the parent pom :

<groupId>com.o2xp</groupId>
    <artifactId>ats-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>ats-parent</name>

    <modules>
        <module>ats-api</module>
        <module>ats-impl</module>
        <module>ats-client</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>com.o2xp.ats.utils.App</start-class>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

        <!-- Version -->
        <immutables.version>2.5.5</immutables.version>

    </properties>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.5.4.RELEASE</version>
                <configuration>
                    <mainClass>com.o2xp.ats.utils.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>

the main class is in a sub module from the module ats-impl which is a module of ats-parent

can you explain me what is wrong with my configuration and if it's possible to maybe have a clear and detailed tutorial it would really help me to understand how this is working.

Try to add repackage goal to the plugin

       <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我已经通过使用以下命令成功执行了mvn exec:java -pl ats-utils -Dexec.mainClass=com.o2xp.ats.utils.App我指定必须从ats-impl模块运行此命令(看看我的pom)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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