找不到模块OpenJDK 12 Maven Eclipse

时间:2019-07-16 07:26:42

标签: java eclipse maven java-module

环境:OpenJDK 12,Maven 3.6.1,Eclipse 4.12,模块是同一工作空间中的2个独立项目。

上下文:我正在尝试编译2个简单的模块。

问题:编译第二个模块时找不到message->模块


第一个模块:


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(带有“模块”路径)完成的,这是我发现的唯一方法。

1 个答案:

答案 0 :(得分:2)

在第二个模块中添加第一个模块作为依赖项:

<dependencies>
  <dependency>
     <groupId>cars</groupId>
     <artifactId>ModuleCars</artifactId>
     <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>

并且您必须使用全新安装来安装第一个模块。