【发布时间】:2019-07-16 07:26:42
【问题描述】:
环境:OpenJDK 12、Maven 3.6.1、Eclipse 4.12、模块是同一工作区中的 2 个独立项目。
上下文:我正在尝试编译 2 个简单的模块。
问题:消息->编译第二个模块时找不到模块
第一个模块:
public class Car{
//Strings attributes
public Car(args){
//set args
}
//getter & setters
}
module ModuleCars {
exports com.org.car; //the class is inside this package
}
POM:
<modelVersion>4.0.0</modelVersion>
<groupId>cars</groupId>
<artifactId>ModuleCars</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
运行 Maven 干净编译:好的
第二个模块:
public class CarFactory {
private static CarFactory instance;
private CarFactory() {
}
public static synchronized CarFactory getInstance() {
if(instance == null) {
instance = new CarFactory();
}
return instance;
}
public Car createCar() {
return new Car("5","Red","01/01/2019");
}
}
module ModuleFactory {
requires transitive ModuleCar;
exports com.org.factory; //the class is inside this package
}
Pom:
<modelVersion>4.0.0</modelVersion>
<groupId>factory</groupId>
<artifactId>ModuleFactory</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
</plugins>
</build>
项目属性: -> Java 构建路径 -> 项目 -> 模块路径-> 添加 ModuleCars
运行 Maven: 干净编译:找不到模块:ModuleCars
更新 1: 模块之间的连接是使用 Eclipse(使用模块路径)进行的,这是我找到的唯一方法。
【问题讨论】:
-
在 Maven 中,第二个模块如何知道第一个模块?您是否有父 POM,或者第二个模块是否从第一个模块已发布到的 Maven 存储库中获取第一个模块?
标签: java eclipse maven java-module