Import of a Java-9-Jigsaw-Maven-Project in Eclipse Oxygen 4.7 does not work
I use:
- JDK 9 build 9-ea+172
- Maven 3.5.0
- Eclipse Oxygen 4.7 RC3 Version 4.7.0.I20170531-2000 from 2017-05-31
- Eclipse-Plugins:
- Eclipse JDT (Java Development Tools) Patch with Java 9 support (BETA) for Oxygen development stream, 1.1.1.v20170526-0728_BETA_JAVA9
- m2e - Maven Integration for Eclipse (includes Incubating components), 1.8.0.20170516-2043
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?
<sourceDirectory>src/main/java/a</sourceDirectory>
? – Operettamodule-info.java
file must be located intosrc/main/java
... – OperettaBy convention, the source code for the module is in a directory that is the name of the module
", see: openjdk.java.net/projects/jigsaw/quick-start. For this you have to do: a) placemodule-info.java
in this directory (in my case insrc/main/java/a
), and b) configure in Maven-POM "<sourceDirectory>src/main/java/a... This project directory layout is correct. It has the advantage that you can easily add further Jigsaw-Modules in the samesrc/main/java
directory. – Herniamodule-info.class
will end up in the root of a jar file which contains the appropriate module and that means you can't have multiple module files in a single Maven module. Having multiple jigsaw-modules within the same/src/main/java
will not really work cause that means you need to create two different jar files one for each module. That is the same issue trying to create two different jar's from that same maven module which will not work. – Operetta<sourceDirectory>src/main/java/a...
in POM, and files in:proj2\a\src\main\java\module-info.java
andproj2\a\src\main\java\a\App.java
. The result is the same with same errors: It does not work in Eclipse. – Herniaproj2/pom.xml
? If yes then move your folders toproj2/src/main/java
...etc. Also for the others..otherwise you are not following the maven conventions... – Operettaproj2
and one module POM inproj2\a
. The more important POM is the last one in theproj2\a
directory, wheresrc/main/java/...
is located. – Herniaproj-a
has only one POM and shows the same errors. You can download it together with config file and screenshot from: bugs.eclipse.org/bugs/attachment.cgi?id=268742 – Hernia