Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 517777

Summary: [9] Running a Java 9 application in Eclipse Oxygen 4.7 does not set the module path
Product: [Eclipse Project] JDT Reporter: Torsten Horn <Torsten.Horn>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: fbricon, jarthana, sarika.sinha, sasikanth.bharadwaj
Version: 4.7   
Target Milestone: BETA J9   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
Additional Infos: Project, Config, Screenshot
none
Pure eclipse project (no Maven) reproducing the issue none

Description Torsten Horn CLA 2017-06-04 05:55:02 EDT
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

Create a new Jigsaw-Maven-Project:

mkdir proj-a\src\main\java\a
cd proj-a

In directory 'proj-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>
  <groupId>proj-a</groupId>
  <artifactId>a</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>
  <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 'proj-a\src\main\java' the file 'module-info.java':

module a { }

In directory 'proj-a\src\main\java\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 proj-a
mvn clean package
java -p target\a-1.0.jar -m a/a.App
-->  
    CLASSPATH:
    Class / Modul:       App from module a
    Layer.Configuration: jdk..., 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:           ...\proj-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?

I have configured Eclipse for JDK 9.
In eclipse.ini I added:
...
-vm
C:\Program Files\Java\jdk-9\bin
-vmargs
...
--add-modules=ALL-SYSTEM
--permit-illegal-access
Comment 1 Torsten Horn CLA 2017-06-04 06:40:13 EDT
Created attachment 268742 [details]
Additional Infos: Project, Config, Screenshot
Comment 2 Fred Bricon CLA 2017-06-04 10:12:15 EDT
Can you try with a stock eclipse, non-maven project?
Comment 3 Torsten Horn CLA 2017-06-06 15:51:17 EDT
What do you mean with "stock eclipse"?
Do you mean installing from "eclipse-java-oxygen-RC2-win32-x86_64.zip" instead of "eclipse-SDK-4.7RC3-win32-x86_64.zip"?
I tried this, but in the result I get the same errors.

Concerning "non-maven project":
That would not be an option for me. I have large maven projects, which I have to import.
Comment 4 Fred Bricon CLA 2017-06-06 16:03:14 EDT
I want to be sure this is an m2e issue, not an Eclipse JDT issue.
I'm asking if you can reproduce the same problem with a non-maven test project.

Simply create a Java project in Eclipse's wizard, copy your test files and see if running the main class works as expected or not
Comment 5 Fred Bricon CLA 2017-06-07 16:42:32 EDT
Created attachment 268800 [details]
Pure eclipse project (no Maven) reproducing the issue

Non-Maven projects yields the same result, so this is a JDT problem.

M2e will most probably need some changes to cope with proper modulepath settings in launch configurations as well, but we'll need JDT to lead the way 1st.
Comment 6 Sarika Sinha CLA 2017-06-08 00:45:20 EDT
Adding JDT Core members!!
Comment 7 Sasikanth Bharadwaj CLA 2017-06-08 02:07:58 EDT
(In reply to comment #5)
> M2e will most probably need some changes to cope with proper modulepath settings
> in launch configurations as well, but we'll need JDT to lead the way 1st.

bug 514760 is meant to cover this
Comment 8 Sarika Sinha CLA 2017-06-08 04:04:24 EDT

*** This bug has been marked as a duplicate of bug 514760 ***
Comment 9 Jay Arthanareeswaran CLA 2017-06-09 02:10:59 EDT
A workaround for the time being is to pass the JVM arguments manually:

-p C:\e\w\j9\Java9\bin -m a/a.App

prints this:

CLASSPATH:           
Class / Modul:       App from module a
Layer.Configuration: java.desktop, jdk.charsets, java.base, ...