使用 java 9 时无法执行 maven-compiler-plugin:3.6.1:testCompile
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48053904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to execute maven-compiler-plugin:3.6.1:testCompile when using java 9
提问by Jim C
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
我确实安装了 java 9
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/
为了简化示例,如果我下载一个非常简单的示例https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/然后我尝试/
mvn clean install package -e
mvn 全新安装包 -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
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:
我有点困惑是什么导致了这个问题。最重要的是,我面临着另一个挑战,这让第一次尝试使用 Java 9 的人变得有点困难:我的 Eclipse 没有正确接受 Java 9。我尝试在刚刚下载的 Eclipse Oxygen 中安装 Java 9 Support它,但我收到“在http://download.eclipse.org/eclipse/updates/none找不到存储库”。而且我无法让这个 mvn 插件将 Java 版本更新为 9(它曾经适用于 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.
这就是我试图从命令行编译 straich 的原因。
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.
我读到 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.
我的直接问题是为了编译我可以检查什么。关于使 Eclipse Oxygen 当前版本与 Java 9 兼容的额外技巧也将受到赞赏。
- Edited
- 已编辑
Eclipse version downloaded for Windows less than 24 hours ago:
不到 24 小时前为 Windows 下载的 Eclipse 版本:
Eclipse Java EE IDE for Web Developers.
面向 Web 开发人员的 Eclipse Java EE IDE。
Version: Oxygen.2 Release (4.7.2) Build id: 20171218-0600
版本:Oxygen.2 发布 (4.7.2) 版本号: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:
在我从 1.9 更改为 9 后,红色错误图标消失了,我现在有了 Java 9。不过,现在我收到了这个错误:
[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:
这对我来说没有意义,因为:
- Edited third time
- 第三次修改
采纳答案by Naman
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
)
简而言之,添加一个缺失/错位的类,以module-info.java
在项目的源根目录中包含项目的模块声明。(例如src/main/java
)
Additionally, note to upgrade to the version 3.7.0of the maven-compiler-plugin
in case you have a comment included in your module-info
class. [The logs seems pretty relevant to this.]
此外,需要注意升级到3.7.0版本的maven-compiler-plugin
情况下,你有一个包含在您的评论module-info
类。[日志似乎与此非常相关。]
Or the other way, if you wish to compile your project with a previous version of Java then use the release
flag as:
或者相反,如果您希望使用以前版本的 Java 编译您的项目,则使用以下release
标志:
<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 Jigsawtherein 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.
随着 Java9 标志着Jigsaw项目的完成,其中引入了Java 平台模块系统 (JPMS),基于 Java 9 及更高版本构建的项目将被模块化。这将包括一个主要的编译类,称为module-info.class
该模块的声明。
The initial draftand eventually The State of the Module Systemdescribes best over the concepts followed and practiced.
该初稿和最终的模块系统的状态描述过的概念遵循和实践的最好的。
An additional trick regard making Eclipse Oxygen current version compatible with Java 9
使 Eclipse Oxygen 当前版本与 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.
AFAIK来自 Eclipse的最新 Oxygen 构建(此时为 Oxygen.2)旨在与 Java9 兼容,不再需要任何额外的插件支持。
Additional Useful Resources:
其他有用资源:
回答by nithya
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.
在第二次编辑中,您必须将 jdk 添加到您的构建路径中。转到 windows->Preferences->Java->installed jre's 并添加 jdk,并检查它。