11

I know that there are a lot question with similar error. I would appreciate before point as duplicate take in account that it only happens with Java 9.

I do have java 9 installed

C:\_pocs\ws_j9\java9-http-client>java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

C:\_pocs\ws_j9\java9-http-client>echo %JAVA_HOME%
C:\Program Files\Java\jdk-9.0.1

To make simple the exemplification, if i download a very simple example https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/ and I try/

mvn clean install package -e

[ERROR] Failed to parse module-info:
[ERROR] With qdox: null
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.925 s
[INFO] Finished at: 2018-01-01T23:43:32+01:00
[INFO] Final Memory: 13M/44M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project http_client: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile (default-testCompile) on project http_client: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:testCompile failed: Failed to parse module-info
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)

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>com.javacodegeeks.java9</groupId>
    <artifactId>http_client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Java9HttpClient</name>
    <description>Java Http Client example</description>
    <properties>
        <java-version>1.9</java-version>

        <maven-compiler-plugin-version>3.6.1</maven-compiler-plugin-version>
        <maven-shade-plugin-version>3.0.0</maven-shade-plugin-version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin-version}</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>${maven-shade-plugin-version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.javacodegeeks.java9.http_client.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I am bit confused what could be causing this issue. On top of this, I am facing another challenge that make it a bit harder for someone trying to use Java 9 for first time: my Eclipse isn't properly accepting Java 9. I tried install Java 9 Support in Eclipse Oxygen which I just downloaded it but I am getting "No repository found at http://download.eclipse.org/eclipse/updates/none". And I can't make this mvn plugin update the Java version to 9 (it used to work properly for Java < 1.8:

    <properties>
        <java-version>1.9</java-version>
...
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                    <verbose>true</verbose>
                </configuration>
            </plugin>

That is the reason I am trying to compile straich from command line.

I read that Java 9 came with new concept of modularity which will help us better organize the packages but I am very limeted if this could drive me to fix my issue. It might be some obvious solution whe someone sees "Failed to parse module-info" but I can't imagine anything usefull to try.

My straight question is what I could check in order to compile. An additional trick regard making Eclipse Oxygen current version compatible with Java 9 will be appreciatte as well.

  • Edited

enter image description here

Eclipse version downloaded for Windows less than 24 hours ago:

Eclipse Java EE IDE for Web Developers.

Version: Oxygen.2 Release (4.7.2) Build id: 20171218-0600

  • Edited second time

After I changed from 1.9 to 9 the red error icon was gone and I have now Java 9. Nevertheless, now I got this error:

[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.542 s
[INFO] Finished at: 2018-01-02T05:19:30+01:00
[INFO] Final Memory: 9M/30M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project http_client: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

Which doesn't make sense to me because:

enter image description here

  • Edited third time

enter image description here

Jim C
  • 3,957
  • 25
  • 85
  • 162
  • It obviously is a jdk or plugin problem . Except the maven-compiler-plugin , i solve this problem by checking every jdk config in my ide(intellij), making sure jdk set right in "project structure" and the "preference" , – cccandy Jan 03 '20 at 04:31

2 Answers2

5

In short, add a missing/misplaced class named module-info.java to include your project's module declaration at your project's source root. (e.g src/main/java)

Additionally, note to upgrade to the version 3.7.0 of the maven-compiler-plugin in case you have a comment included in your module-info class. [The logs seems pretty relevant to this.]


Or the other way, if you wish to compile your project with a previous version of Java then use the release flag as:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.7.0</version>
    <configuration>
        <release>8</release>
        <verbose>true</verbose>
    </configuration>
</plugin>

Concepts

With Java9 marking the completion of the project Jigsaw therein introducing the Java Platform Module System (JPMS), projects build on Java version 9 and above would be modularised. This would include a primary compiled class called module-info.class which is that module's declaration.

The initial draft and eventually The State of the Module System describes best over the concepts followed and practiced.


An additional trick regard making Eclipse Oxygen current version compatible with Java 9

AFAIK the latest Oxygen builds (Oxygen.2 at this point in time) from Eclipse are meant to be Java9 compatible without any additional plugin support anymore.


Additional Useful Resources:

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • What do you mean by "add a missing/misplaced class named module-info.java to include your project's module declaration at your project's source root"? Do you mean add "--add-modules=ALL-SYSTEM " in eclipse.ini qs guided here https://wiki.eclipse.org/Configure_Eclipse_for_Java_9#Configure_Eclipse_for_Java_9_modules ? Everytime I use maven project I get Java 1.5 in Eclipse when I run maven update although I don't have 1.5. I fix this by especifing the java version in pom.xml. I mean, by setting maven-compiler-plugin to 1.8 has fixed immediatly this. But it is not working for 1.9 (see image) – Jim C Jan 02 '18 at 03:53
  • @JimC No I don't mean add modules. Please look into the compatibility of the Eclipse version and maven dependencies versions you are using with Java9. I meant to state the difference between developing and compiling with JDK9 VS building with the previous JDK version and compiling with that JDK version still being on Java9 on your machine. Also, if your project is a Java9 module, you must have a `module-info.java` class. Refer to the resources links for details on how to create a java9 module. – Naman Jan 02 '18 at 04:01
  • 3
    @JimC By the way, from screenshots one more thing. I believe it should be `9` and not `1.9`. – Naman Jan 02 '18 at 04:03
  • 1
    Thanks, I am making progress. Do you know why I could get "[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project http_client: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?" when compiling from Eclipse but no error at all when compile throw windos console? – Jim C Jan 02 '18 at 04:29
  • I succesfully compiled in command line but I couldn't run it in Eclipse. When Itried to debug I got the above error (see third edition added). I guess when you said "if your project is a Java9 module, you must have a module-info.java class" you meaned the module-info.java pasted above. PS: I am focused in running for first time Java 9 application in Eclipse. I don't care at this moment about Java 8 application running with Java 9 JDK/JRE. – Jim C Jan 02 '18 at 04:44
  • 2
    Few links that you might want to look at:- 1. Eclipse bug [Updating to Oxygen.1a (4.7.1a) does not uninstall/overwrite Java 9 BETA](https://bugs.eclipse.org/bugs/show_bug.cgi?id=526065).. 2. Look at the command executed by Eclipse and [understand the difference between classpath and modulepath](https://stackoverflow.com/questions/47467663/java-9-httpclient-java-lang-noclassdeffounderror-jdk-incubator-http-httpclient/47468106#47468106) while executing your Main.class. Also, would suggest asking independent questions if you could avoid extending this infinitely. – Naman Jan 02 '18 at 05:06
-1

in the second edit, you have to add jdk to your build path. Go to windows->Preferences->Java->installed jre's and add the jdk, and check it.

nithya
  • 1