2

I created a simple Hello World main class and a module-info.java file within a Maven project in Eclipse Oxygen.1a Release (4.7.1a), running on Java 9.0.1.

When I try to start the main class with right-click - Run As Java Application I get the error:

Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.github.gv2011.quarry.modules.moda not found

I can successfully run it from the command line from the target/classes directory:

java -p . -m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello
Hello

If I manually edit the created launch configuration and add the VM arguments

-p target/classes
-m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello

it works, too.

Is there a more comfortable way to start main classes from Eclipse without that manual launch-configuration editing?

Main class:

package com.github.gv2011.quarry.modules.moda;
public class Hello {
  public static void main(final String[] args) {
    System.out.println("Hello");
  }
}

module-java:

module com.github.gv2011.quarry.modules.moda {
  exports com.github.gv2011.quarry.modules.moda;
}

Related question: Eclipse - module not found when adding module-info.java

The launch configuration created by Eclipse (not working) is this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
        <listEntry value="/quarry-modules-a/src/main/java/com/github/gv2011/quarry/modules/moda/Hello.java"/>
    </listAttribute>
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
        <listEntry value="1"/>
    </listAttribute>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.github.gv2011.quarry.modules.moda.Hello"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quarry-modules-a"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
</launchConfiguration>

The working one is that:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
        <listEntry value="/quarry-modules-a/src/main/java/com/github/gv2011/quarry/modules/moda/Hello.java"/>
    </listAttribute>
    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
        <listEntry value="1"/>
    </listAttribute>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.github.gv2011.quarry.modules.moda.Hello"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="quarry-modules-a"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-p target/classes&#13;&#10;-m com.github.gv2011.quarry.modules.moda/com.github.gv2011.quarry.modules.moda.Hello"/>
</launchConfiguration>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gustave
  • 3,359
  • 4
  • 31
  • 64
  • The args added seems redundant for any IDE if forced to be added. Not sure what the default java command Eclipse executes. But IDEs should take care of the command line args used for a minimal Main class execution of a project based on Java version 9. On a side note, isn't this a duplicate where in you could have asked for alternates in the other question itself(owing to the fact the question has been self answered there as well)? – Naman Dec 09 '17 at 12:26
  • Is the project configuration set to a java9 JRE/JDK? – the8472 Dec 09 '17 at 13:05
  • @the8472: Yes, it is. – Gustave Dec 09 '17 at 13:06
  • 2
    See https://bugs.eclipse.org/bugs/show_bug.cgi?id=528361 – Gustave Dec 09 '17 at 18:04
  • @marc_s About your edit of the question: I appreciate if you improve the formatting, but I think it is not a good idea to modify the real-world-tested code parts. It is "quarry", not "query". – Gustave Jun 12 '18 at 21:45

2 Answers2

1

This will be fixed in Eclipse Photon (I've checked with 4.8M6).

If you don't want to wait until June, you can download the current milestone build from https://www.eclipse.org/downloads/index-developer.php

Setting the modulepath was previously simply not implemented in m2e for Oxygen (it was implemented for Photon in https://bugs.eclipse.org/bugs/show_bug.cgi?id=529398.)

Till Brychcy
  • 2,876
  • 1
  • 18
  • 28
0

As pointed in the comments, there is an Eclipse bug which unfortunately got little attention (this looks like a blocker for me which should have been fixed immediately).

As for now, I think this is the simplest workaround:

  • Go to your launch configuration and find VM arguments.
  • Enter -p ${project_classpath:module_name} (substitute module_name with a real module name).
ZhekaKozlov
  • 36,558
  • 20
  • 126
  • 155