Torsten Horn
Torsten Horn

Reputation: 71

Import of a Java-9-Jigsaw-Maven-Project in Eclipse Oxygen 4.7 does not work

Import of a Java-9-Jigsaw-Maven-Project in Eclipse Oxygen 4.7 does not work

I use:

Creata a new Jigsaw-Maven-Project:

mkdir proj1\a\src\main\java\a\a
cd proj1

In directory proj1 the file pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>test</groupId>
  <artifactId>Proj1</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <modules>
    <module>a</module>
  </modules>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
          <source>9</source>
          <target>9</target>
          <showWarnings>true</showWarnings>
          <showDeprecation>true</showDeprecation>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

In directory proj1\a the file pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>test</groupId>
    <artifactId>Proj1</artifactId>
    <version>1.0</version>
  </parent>
  <artifactId>a</artifactId>
  <packaging>jar</packaging>
  <build>
    <sourceDirectory>src/main/java/a</sourceDirectory>
  </build>
</project>

In directory proj1\a\src\main\java\a the file module-info.java:

module a { }

In directory proj1\a\src\main\java\a\a the file App.java:

package a;

public class App {
   public static void main( String[] args ) {
      System.out.println( "CLASSPATH:           " + System.getProperty( "java.class.path" ) );
      System.out.println( "Class / Modul:       " + App.class.getSimpleName() + " from " + App.class.getModule() );
      java.lang.ModuleLayer lr = App.class.getModule().getLayer();
      if( lr != null ) {
         System.out.println( "Layer.Configuration: " + lr.configuration() );
      } else {
         System.out.println( "Error:               ModuleLayer is null" );
      }
   }
}

Running the project on command line:

cd proj1
mvn clean package
java -p a\target\a-1.0.jar -m a/a.App  

-->

CLASSPATH:
Class / Modul:       App from module a
Layer.Configuration: java..., ...  

-->
Works perfect without error (CLASSPATH is empty, name from getModule() is correct, and ModuleLayer is valid).

Opening the project in IntelliJ IDEA 2017.2 EAP
-->
Works perfect without error (CLASSPATH is empty, name from getModule() is correct, and ModuleLayer is valid).

Importing the project in Eclipse Oxygen 4.7 RC3:
-->

CLASSPATH:           ...\proj1\a\target\classes
Class / Modul:       App from unnamed module @68f7aae2
Error:               ModuleLayer is null

-->
All three lines are wrong.

How can I avoid this errors?

Upvotes: 2

Views: 1092

Answers (2)

Akash Mishra
Akash Mishra

Reputation: 712

Typically, all the classes within a single 'src' folder should be enclosed and packaged in a single module-info.java Also, the module-info.java should be immediately within src package. For you, the classes within the directory proj1\a\src\ should be combined. And you should maintain the module-info.java at the same level. Follow this blog for complete deployment.

Upvotes: 0

Torsten Horn
Torsten Horn

Reputation: 71

This is a bug in Eclipse Oxygen 4.7 RC3, see:
Eclipse Bug 517777: Running a Java 9 application in Eclipse Oxygen 4.7 does not set the module path (https://bugs.eclipse.org/bugs/show_bug.cgi?id=517777)
and
Eclipse Bug 514760: Run configuration should support notion of modules (https://bugs.eclipse.org/bugs/show_bug.cgi?id=514760)

Upvotes: 2

Related Questions