Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse issue with java 9 and maven

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.

like image 559
venergiac Avatar asked Nov 04 '17 10:11

venergiac


1 Answers

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

like image 127
howlger Avatar answered Nov 04 '22 16:11

howlger