7

I installed Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200 supporting Java 9.

With suggested configuratio on eclipse.ini

-vm
C:\Program Files\Java\jdk-9\bin\javaw.exe
--add-modules=ALL-SYSTEM

I have developed by java 9 (java 9 modularity) code project to test dependency injection as pure Java prject from eclipse, but when I have integrated Maven running my from eclipse I get systematically the following error

Error occurred during initialization of boot layerjava.lang.module.FindException: Module com.my.module.hello.test not found

the only solution was to add on VM arguments

--module-path target/classes;../my-module-api/target/classes;../my-module-it/target/classes --module com.my.module.hello.test/com.my.module.hello.Reflection

enter image description here

Indeed if add to Vm arguments the verbose parameter I can see during loading

... [0.694s][info][class,load] java.lang.NamedPackage source: jrt:/java.base [0.697s][info][class,load] com.my.module.hello.MyHello source: file:/C:/Users/212442540/workspace-training/my-module-prj/my-module/target/classes/ [0.698s][info][class,load] java.lang.module.ModuleDescriptor$$Lambda$24/2114889273 source: java.lang.module.ModuleDescriptor ...

when I remove the "--module-path" parameter this line disappear.

Notice: Eclipse is able to work correctly during the compilation or editing. See the completition and so on ..

enter image description here

I have added modpath dependencies also to my project

Forcing dependencies on project config

I added the dependencies manually on the project config enter image description here

So it seems that Eclipse is able to compile java 9 modules, but it is not able to run module if integrated with maven.

Forcing dependencies on Configratin Run I have also added the dependencies manually enter image description here figure 1

but eclipse continues to remove them.

Before:

manually

figure 2

After run eclipse restores:

after save figure 3

It seems that eclipse reset systematically the configuration if integrated with maven.

Omid
  • 5,823
  • 4
  • 41
  • 50
venergiac
  • 7,469
  • 2
  • 48
  • 70
  • isn't that code a demo of module functionality - is it even expected to work without those parameters? – eis Nov 04 '17 at 10:58
  • The java command should be java --module-path target/classes;../my-module-api/target/classes;../my-module-it/target/classes --module com.my.module.hello.test/com.my.module.hello.Reflection but I'm expecting eclipse do this work for me – venergiac Nov 04 '17 at 11:02
  • have you went through any eclipse instructions to set them up, such as [this one](https://stackoverflow.com/questions/44403070/how-do-i-add-modules-to-the-eclipse-oxygen-module-path-for-a-project)? – eis Nov 04 '17 at 11:14
  • yes done ..tx ..-vm C:\Program Files\Java\jdk-9\bin\javaw.exe --add-modules=ALL-SYSTEM – venergiac Nov 04 '17 at 11:15
  • The recommended way is to use _Dependencies_ only without _VM arguments_. If the _my-module_ project is a Java 9 module, it must be on the modulepath, not on the classpath. – howlger Nov 04 '17 at 11:22
  • @hwolegee yes it is – venergiac Nov 04 '17 at 11:23
  • have you checked if the problem is with eclipse-maven integration? does your setup work without maven? – eis Nov 04 '17 at 11:25
  • yes I think so. It works with "pure" maven and "pure" java, but not from eclipse. Also eclipse is able to compile correctly but during Run continues to remove modules from my "Run Configuration" – venergiac Nov 04 '17 at 11:27
  • Your run configuration contains conflicting settings: your _VM arguments_ are in conflict with the main class and _Dependencies_. – howlger Nov 04 '17 at 11:30
  • @venergiac what I meant to ask is if your setup works from eclipse but without maven, so if the problem might be in maven-eclipse integration. – eis Nov 04 '17 at 11:32
  • 1
    @eis : yes before Maven it worked now no. – venergiac Nov 04 '17 at 11:43
  • @venergiac Here is my video how to create a Java 9 module application with Eclipse Oxygen.1a (without Maven): https://www.youtube.com/watch?v=wI3VC1lhbK8 – howlger Nov 04 '17 at 11:45
  • @howlegr: removed Run configuration, cleaned project, remove allcm arguments restarted eclipse figure 2 vs figure 3 – venergiac Nov 04 '17 at 11:48
  • @venergiac add that detail into the question - its important information. The main point of the question should then be eclipse-maven -integration regarding java 9 modules. – eis Nov 04 '17 at 11:53
  • @eis done tx I added more info – venergiac Nov 04 '17 at 12:07
  • @howlegr: yes tx it works also for me without maven – venergiac Nov 04 '17 at 12:07

1 Answers1

6

I can reproduce your problem, it looks like a bug of M2Eclipse.

Please report it to Eclipse. Bug 526838 - Eclipse wrong Module dependencies on Run configuration when integrated with maven

As workaround use an External Tool Configuration instead of an Java application run configuration:

  1. Run > External Tool > External Tool Configurations...
  2. Select Program and click the New launch configuration icon in the in the upper left corner
  3. Enter the following values:
     
    Location: C:\windows\system32\cmd.exe
     
    Working Directory: ${workspace_loc:/my-module}
     
    Arguments:

    /C java
    -p target/classes;../my-module-api/target/classes;../my-module-it/target/classes
    -m com.my.module.hello.test/com.my.module.hello.Reflection
  4. Click Run

howlger
  • 31,050
  • 11
  • 59
  • 99
  • @venergiac Thanks for reporting it. I added the link to the bug in my answer. – howlger Nov 04 '17 at 15:17
  • @giusy Yes, I guess so, because manually inserted classpath/modulepath entries have disappeared when I reopen the run configuration. But I'm not sure if it is a m2e or a JDK bug. – howlger Nov 10 '17 at 08:29