我知道有很多类似错误的问题。我会很感激,因为重复考虑到它只发生在 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。我尝试在刚刚下载的 Eclipse Oxygen 中安装 Java 9 支持它,但我收到“在 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 带来了模块化的新概念,这将帮助我们更好地组织包,但如果这能促使我解决我的问题,我会感到非常沮丧。当有人看到“无法解析模块信息”时,这可能是一些明显的解决方案,但我无法想象有什么有用的尝试。
我的直接问题是为了编译我可以检查什么。关于使 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
的缺失/放错位置的类在项目的源代码根目录中包含项目的模块声明。 (例如 src/main/java
)
此外,注意 upgrade to the version 3.7.0的 maven-compiler-plugin
如果你有一个 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其中介绍了Java Platform Module System (JPMS) ,构建在 Java 版本 9 及更高版本上的项目将被模块化。这将包括一个名为 module-info.class
的主要编译类这是module's declaration .
initial draft最终The State of the Module System最好地描述了所遵循和实践的概念。
An additional trick regard making Eclipse Oxygen current version compatible with Java 9
据我所知latest Oxygen builds (Oxygen.2 at this point in time)来自 Eclipse 的意味着与 Java9 兼容,不再需要任何额外的插件支持。
其他有用资源:
关于java - 使用 java 9 时无法执行 maven-compiler-plugin :3. 6.1:testCompile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48053904/