我正在创建一个Spring Boot多模块项目。模块 A 依赖于模块 B。
模块 A 在我以分解形式运行时运行良好。.
mvn spring-boot:run
但是我无法将jar与依赖项一起打包这样我就可以执行它
java -jar Module-A.jar
模块 A pom.xml如下:
<parent>
<artifactId>Module-Test</artifactId>
<groupId>com.module</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Module-A</artifactId>
<packaging>jar</packaging>
<properties>
<start-class>com.NotifyApp</start-class>
<main.class>com.NotifyApp</main.class>
</properties>
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
无法在项目模块 A 上执行目标 org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:重新打包(默认):目标的执行默认值 org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:重新打包失败:源必须引用r 到现有文件
父绒球.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>Module-Test</artifactId>
<groupId>com.module</groupId>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>Module-A</module>
<module>Module-B</module>
<module>Module-C</module>
</modules>
<packaging>pom</packaging>
<parent>
<artifactId>Module-Parent</artifactId>
<groupId>com.parent</groupId>
<version>1.0.2</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-C</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>starter-service</artifactId>
<version>${starter.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
我通常将此插件 https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html 用于 maven,它会在运行时将所有依赖项 jar 放入目标/依赖项中
mvn clean package
然后我把jar复制到一个文件夹(我通常称之为lib),并在我的类路径中包含lib/*。最终运行脚本通常如下所示
java -cp lib/*: my.package.MySpringBootMain
<</div>
div class="one_answers"> 删除
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
不需要。
在模块 A 的 pom 中添加模块 B 的依赖关系.xml
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
对模块 B 使用 maven clean编译包安装命令,先构建模块 B,然后在模块 A 上运行 maven clean 编译包。这会将模块 B 输出到模块 A 中。
模块 B 的 pom 中不需要模块 A 的引用.xml
你肯定知道,但你可以从这个链接初始化你的项目Spring Initializr,它会自动生成您需要的配置