【发布时间】:2018-09-17 19:20:04
【问题描述】:
我已经创建了一个多模块 spring boot maven 项目。
但是当我使用
mvn clean package -pl module2 spring-boot:run
在控制台中。它告诉我 module1 中的某些类找不到。
但是我在module2中添加了依赖。 module2 是最终的项目。
项目结构如下。
父项目的 pom.xml
<groupId>com.example</groupId>
<artifactId>multi-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
...
</properties>
</dependencies>
...
<dependencyManagement>
...
</dependencyManagement>
module1中的pom:
<groupId>com.example</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>com.example</groupId>
<artifactId>multi-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
module2中的pom.xml:
<artifactId>personalinfo</artifactId>
<name>personalinfo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>com.example</groupId>
<artifactId>multi-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>module1</artifactId>
<version>0.0.1-SNAPSHOT</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>
【问题讨论】:
-
你能显示错误吗?
-
您是否先从 root 完成了
mvn install? -
当我在根目录中使用 mvn clean package 时。它运作良好。但我想知道如何使用“mvn clean package -pl [targetModule] spring-boot:run”来运行spring boot模块。
-
报错如下:
[ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /src/main/java/com/example/dao/ClassInModule1.java:[12,29] package com.package.in.module1 does not exists
标签: maven spring-boot