使用Java 9时无法执行maven-compiler-plugin:3.6.1:testCompile [英] Failed to execute maven-compiler-plugin:3.6.1:testCompile when using java 9

查看:156
本文介绍了使用Java 9时无法执行maven-compiler-plugin:3.6.1:testCompile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多错误类似的问题.在此之前,我将不胜感激,因为重复考虑到它仅在Java 9中发生.

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.

我确实安装了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

为简化示例,如果我下载一个非常简单的示例 https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/,我尝试/

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全新安装软件包-e

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>

我有点困惑可能导致此问题的原因.最重要的是,我面临着另一个挑战,这对于初次尝试使用Java 9的人来说有点困难:我的Eclipse无法正确接受Java9.我尝试在刚刚下载的Eclipse Oxygen中安装Java 9支持它,但我收到在http://download.eclipse.org/eclipse/updates /none ".而且我无法使该mvn插件将Java版本更新为9(它过去在Java< 1.8上正常工作:

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>

这就是我试图从命令行编译straich的原因.

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

我读到Java 9带有新的模块化概念,它将帮助我们更好地组织软件包,但是如果这可以促使我解决问题,我会感到非常困惑.有人看到解析模块信息失败"可能是一些显而易见的解决方案,但是我无法想象有什么有用的尝试.

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.

我的直接问题是我可以检查哪些内容以进行编译.使Eclipse Oxygen当前版本与Java 9兼容的另一个技巧也是赞赏.

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.

  • 已编辑

不到24小时前为Windows下载了Eclipse版本:

Eclipse version downloaded for Windows less than 24 hours ago:

面向Web开发人员的Eclipse Java EE IDE.

Eclipse Java EE IDE for Web Developers.

版本:氧气2释放(4.7.2) 版本号:20171218-0600

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

  • 第二次编辑

从1.9更改为9后,红色错误图标消失了,我现在拥有Java9.但是,现在出现了此错误:

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:

  • 第三次编辑

推荐答案

简而言之,添加一个名为module-info.java的丢失/放错位置的类,以将项目的模块声明包含在项目的源根目录中. (例如src/main/java)

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)

此外,请注意升级到版本3.7.0 (如果您有 注释)中的您的module-info. [日志似乎与此有关.]

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.]

或者,如果您希望使用Java的早期版本编译项目,请使用

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>


概念

使用Java9标记项目的完成拼图,其中引入了 Java平台模块系统(JPMS),基于Java版本9及更高版本的项目将被模块化.这将包括一个名为module-info.class的主要编译类,即模块的声明.


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.

使Eclipse Oxygen当前版本成为一个额外的技巧 与Java 9兼容

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

AFAIK 最新的氧气生成器(此时为Oxygen.2) 来自Eclipse的目的是要与Java9兼容,而不再需要任何其他插件支持.

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.

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆