1

I am struggling to get my Eclipse able to run and debug a simple Java 9 application. I have found several suggestions and I have tried all of them without any success. To summarize, here are all I have read in the last 5 hours:

  • in Java 9 you can't use package_name/something/*.jar (the issue is pointed to be *.jar)
  • you must setup Java 9 in eclipse.ini
  • you must place module-info.java under src directory
  • you setup jre instead of jdk in (Preference>Installed JREs>Add...)

The closest question I found to mine is How do I add modules to the Eclipse Oxygen module path for a project? but without accepted answer and it seems to be older than current Eclipse version.

In fact, I can compile successfully both in Eclipse (right click>run as>Maven install...) or using mvn clean package install straight from command line. Nevertheless, I can run the application straight from command line but I can't run it from Eclipse. I do consider this usefull since the next step will be debug.

The simple application is downlowaded from https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/

I made only two changes in the original application pom (see Failed to execute maven-compiler-plugin:3.6.1:testCompile when using java 9 for deeper details). I just upgraded maven-compiler-plugin-version to 3.7 and maven-compiler-plugin I changed from 1.9 to 9 and then I can compile it in Eclipse.

Here is my current eclipse.ini where I manually changed the java version:

-startup
plugins/org.eclipse.equinox.launcher_1.4.0.v20161219-1356.jar
--launcher.library
C:\Users\dca\.p2\pool\plugins\org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.551.v20171108-1834
-product
org.eclipse.epp.package.jee.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
C:\Program Files\Java\jre-9.0.1\bin
-vmargs
-Dosgi.requiredJavaVersion=1.9
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=1.9
-Xms256m
-Xmx1024m
--add-modules=ALL-SYSTEM
-Declipse.p2.max.threads=10
-Doomph.update.url=http://download.eclipse.org/oomph/updates/milestone/latest
-Doomph.redirection.index.redirection=index:/->http://git.eclipse.org/c/oomph/org.eclipse.oomph.git/plain/setups/

Here is how I successfully run the application:

C:\_EclipseJava9\WSs\ws\java9-http-client\target>java -jar --add-modules=jdk.incubator.httpclient http_client-0.0.1-SNAPSHOT.jar
WARNING: Using incubator modules: jdk.incubator.httpclient
Running synchronous HTTP Client examples

Assuming I shoud setup "--add-modules=jdk.incubator.httpclient" in Eclipse I tried it without success:

enter image description here

  • Edited

enter image description here

enter image description here

enter image description here

Naman
  • 27,789
  • 26
  • 218
  • 353
Jim C
  • 3,957
  • 25
  • 85
  • 162
  • 1
    Could you update the question with the java command eventually executed by Eclipse before you get that error? – Naman Jan 02 '18 at 12:33
  • @nullpointer, please, if you have other thing mind different from the pictures I just pasted, could you make it clearer? I guess you were expecting the real command triggered by Eclipse but I don't know how to get it. Certainlly, Eclipse transformed the three configurations above in something like "java -jar ... --some_arguments ..." but I don't know how to get the exactly command ran by Eclipse. If it is relevant, can you guide me? Just to put all in same page, I believe you saw that from command line I successfully ran the application. – Jim C Jan 02 '18 at 13:30
  • 1
    The reason I was asking you to get to know the command is actually that I am not using Eclipse either. Maybe this could help you https://stackoverflow.com/questions/9477534/how-to-know-the-command-line-used-by-eclipse-to-run-the-java-program detail the command used during your run. – Naman Jan 02 '18 at 14:28
  • Really nice Eclipse trick. Here you are: "C:\Program Files\Java\jdk-9.0.1\bin\javaw.exe" --add-modules=jdk.incubator.httpclient -Dfile.encoding=Cp1252 -p null -classpath C:\_EclipseJava9\WSs\ws\java9-http-client\target\classes -m com.javacodegeeks.java9.http_client.synchronous/com.javacodegeeks.java9.http_client.Main – Jim C Jan 02 '18 at 15:29
  • 1
    Seems like eclipse is using the classpath instead of modulepath which is wierd for a Java9 based project. – Naman Jan 02 '18 at 16:44
  • 1
    Make sure, `http_client-0.0.1-SNAPSHOT.jar` is on your modulepath of the run configuration (tab _Dependencies_ or via _Project > Properties: Java Build Path:_ tab _Libraries_). `eclipse.ini` is only to run Eclipse, not for the applications you run from inside of Eclipse (by the way `eclipse.ini` should not contain the lines `--add-modules=ALL-SYSTEM` and `-Dosgi.requiredJavaVersion=1.9` twice). Make also sure to use the latest version of Eclipse (currently Oxygen.2): _Help > Check for Updates_. – howlger Jan 02 '18 at 17:14
  • @nullpointer, and how can I fix "Seems like eclipse is using the classpath instead of modulepath which is wierd for a Java9 based project"? – Jim C Jan 03 '18 at 08:45
  • @howlger, if you can setup your comment as answer I would choose it as answer. I fixed by Project > Properties: Java Build Path: tab Libraries and manually added the http_client-0.0.1-SNAPSHOT.jar under Modulepath. It seems a bit different solution than mentioned by nullpointer but I don't which is more effective or if both are exactly the same. – Jim C Jan 03 '18 at 09:07
  • 1
    @nullpointer, I have no arguments at all against be set as dupplicate. I really searched hard and I didn't see that (you can see I mentioned several suggestions tried before wrote this question). BTW, I totally agree with you it is exactly the same issue with different tentatives to fix before start the question – Jim C Jan 03 '18 at 09:10
  • 1
    @JimC Adding `http_client-0.0.1-SNAPSHOT.jar` to the modulepath of the projects requires running a Maven build to update the JAR to see the latest version of the classes. In contrast, launch configurations with `-p ${workspace_loc:java9-http-client}/target/classes -m ...` as VM argument use the saved Java files (which are compiled on save if _Project > Build Automatically_ is enabled). – howlger Jan 03 '18 at 17:14

0 Answers0