0

父项目maven

<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
<modules>
    <module>module1</module>
    <module>module2</module>
</modules>

<properties>
    <revision>0.1.10-SNAPSHOT</revision>
</properties>

<build>
    <plugins>
        <plugin>
             flatten-maven-plugin
              ...
        </plugin>
    </plugin>
<build>

孩子 1 个模块

<parent>
    <artifactId>artifactId</artifactId>
    <groupId>groupId</groupId>
    <version>${revision}</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module1</artifactId>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

孩子 2 模块

<parent>
    <artifactId>artifactId</artifactId>
    <groupId>groupId</groupId>
    <version>${revision}</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>module2</artifactId>
<dependencies>
    <dependency>
        <groupId>groupId</groupId>
        <artifactId>module1</artifactId>
        <version>${project.version}</version>
    </dependency>
</dependencies>

module1是springboot项目,需要打包成可执行jar,module2需要部署到nexus 现在,module2上传到nexus成功了,但是通过java -jar无法启动module1

4

2 回答 2

0

在module1中添加构建可以解决问题

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>{version}</version>
            <configuration>{mainClass}</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
于 2020-12-08T08:29:47.110 回答
0

为模块创建 jar 时,该 jar 必须包含所有依赖项 jar。这种类型的 jar 称为 Fat jar 或可执行 jar。在 module1 的 pom.xml 中添加以下标签,这将在其中创建和打包所有依赖项 jar。注意:我可以看到您已经添加了“spring-boot-maven-plugin”,但是您错过了提供 Spring boot 主类和重新打包目标。

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <mainClass>{Your spring boot main class}</mainClass>
            </configuration>

            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
           </executions>

        </plugin>
    </plugins>
</build>
于 2020-12-09T13:00:37.990 回答