使用 java 9 时无法执行 maven-compiler-plugin:3.6.1:testCompile
Failed to execute maven-compiler-plugin:3.6.1:testCompile when using java 9
我知道有很多类似错误的问题。我会很感激,因为重复考虑到它只发生在 Java 9.
我确实安装了 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
为了简化示例,如果我下载一个非常简单的示例 https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/ 并尝试/
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 没有正确接受 Java 9。我尝试安装 Java 9 在 Eclipse Oxygen 中的支持,我刚刚下载了它,但我得到了 "No repository found at 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>
这就是我尝试从命令行编译 straich 的原因。
我读到 Java 9 带来了模块化的新概念,这将帮助我们更好地组织包,但如果这能促使我解决我的问题,我会感到非常沮丧。当有人看到 "Failed to parse module-info" 时,这可能是一些明显的解决方案,但我无法想象有什么有用的尝试。
我的直接问题是为了编译我可以检查什么。关于使 Eclipse Oxygen 当前版本与 Java 9 兼容的额外技巧也将受到赞赏。
- 已编辑
不到 24 小时前为 Windows 下载的 Eclipse 版本:
面向 Web 开发人员的 Eclipse Java EE IDE。
版本:Oxygen.2 发布 (4.7.2)
构建 ID:20171218-0600
- 第二次编辑
在我从 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?
这对我来说没有意义,因为:
- 第三次编辑
简而言之,添加一个名为 module-info.java
的 missing/misplaced class 以在项目的源代码根目录中包含项目的模块声明。 (例如 src/main/java
)
此外,请注意 upgrade to the version 3.7.0 of the maven-compiler-plugin
in case you have a comment included in your module-info
class。 [日志似乎与此非常相关。]
或者相反,如果您希望使用以前版本的 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>
概念
用Java9标记项目完成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。
initial draft and eventually The State of the Module System 描述了遵循和实践的概念。
An additional trick regard making Eclipse Oxygen current version
compatible with Java 9
据我所知,来自 Eclipse 的 latest Oxygen builds (Oxygen.2 at this point in time) 意味着 Java9 兼容,不再需要任何额外的插件支持。
其他有用资源:
在第二次编辑中,您必须将 jdk 添加到构建路径中。转到 windows->Preferences->Java->installed jre's 并添加 jdk,然后检查它。
我知道有很多类似错误的问题。我会很感激,因为重复考虑到它只发生在 Java 9.
我确实安装了 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
为了简化示例,如果我下载一个非常简单的示例 https://examples.javacodegeeks.com/core-java/java-9-httpclient-example/ 并尝试/
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 没有正确接受 Java 9。我尝试安装 Java 9 在 Eclipse Oxygen 中的支持,我刚刚下载了它,但我得到了 "No repository found at 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>
这就是我尝试从命令行编译 straich 的原因。
我读到 Java 9 带来了模块化的新概念,这将帮助我们更好地组织包,但如果这能促使我解决我的问题,我会感到非常沮丧。当有人看到 "Failed to parse module-info" 时,这可能是一些明显的解决方案,但我无法想象有什么有用的尝试。
我的直接问题是为了编译我可以检查什么。关于使 Eclipse Oxygen 当前版本与 Java 9 兼容的额外技巧也将受到赞赏。
- 已编辑
不到 24 小时前为 Windows 下载的 Eclipse 版本:
面向 Web 开发人员的 Eclipse Java EE IDE。
版本:Oxygen.2 发布 (4.7.2) 构建 ID:20171218-0600
- 第二次编辑
在我从 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?
这对我来说没有意义,因为:
- 第三次编辑
简而言之,添加一个名为 module-info.java
的 missing/misplaced class 以在项目的源代码根目录中包含项目的模块声明。 (例如 src/main/java
)
此外,请注意 upgrade to the version 3.7.0 of the maven-compiler-plugin
in case you have a comment included in your module-info
class。 [日志似乎与此非常相关。]
或者相反,如果您希望使用以前版本的 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>
概念
用Java9标记项目完成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。
initial draft and eventually The State of the Module System 描述了遵循和实践的概念。
An additional trick regard making Eclipse Oxygen current version compatible with Java 9
据我所知,来自 Eclipse 的 latest Oxygen builds (Oxygen.2 at this point in time) 意味着 Java9 兼容,不再需要任何额外的插件支持。
其他有用资源:
在第二次编辑中,您必须将 jdk 添加到构建路径中。转到 windows->Preferences->Java->installed jre's 并添加 jdk,然后检查它。