【问题标题】:Launch multi module maven/spring project启动多模块 maven/spring 项目
【发布时间】:2018-02-02 04:52:34
【问题描述】:

我是 maven 的新手,我已经完成了我的应用程序,我可以从 eclipse 中启动它,当我运行 mvn clean package 时没有错误,但我尝试用 mvn spring-boot:run 启动它,我有这个错误:

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)

但我已经在父 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>

主类位于 ats-impl 模块的子模块中,该模块是 ats-parent 的一个模块

你能解释一下我的配置有什么问题吗?如果有可能有一个清晰而详细的教程,它真的会帮助我理解它是如何工作的。

【问题讨论】:

    标签: java spring maven spring-mvc spring-boot


    【解决方案1】:

    尝试在插件中添加repackage目标

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2022-01-08
        • 2015-10-10
        • 1970-01-01
        • 2014-06-02
        • 2016-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多