tec
tec

Reputation: 1149

module not found OpenJDK 12 Maven Eclipse

Environment: OpenJDK 12, Maven 3.6.1, Eclipse 4.12, Modules are 2 separate projects in the same workspace.

Context: I'm trying to compile 2 simple modules.

Issue: message-> module not found when compiling 2nd module


1st Module:


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>

Run Maven clean compile: ok


2nd module:


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>

Project Properties: -> Java Build Path -> Projects -> Module Path-> Add ModuleCars

Run Maven: clean compile: module not found: ModuleCars

Update 1: The conection between the modules is made with Eclipse (with the Module path), is the only way I have found.

Upvotes: 0

Views: 449

Answers (1)

Qartit Sofiane
Qartit Sofiane

Reputation: 36

Add in your second module the first module as dependency:

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

And you have to install your first Module using clean install.

Upvotes: 2

Related Questions