我知道有很多类似错误的问题。在此之前我会很感激,因为重复考虑到它只发生在 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 干净安装包 -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 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>
这就是我试图从命令行编译 straich 的原因。
我读到 Java 9 带来了模块化的新概念,这将帮助我们更好地组织包,但如果这能促使我解决我的问题,我会非常有限。当有人看到“无法解析模块信息”时,这可能是一些明显的解决方案,但我无法想象有什么有用的尝试。
我的直接问题是我可以检查什么以便编译。关于使 Eclipse Oxygen 当前版本与 Java 9 兼容的另一个技巧也将受到重视。
- 已编辑
不到 24 小时前为 Windows 下载的 Eclipse 版本:
面向 Web 开发人员的 Eclipse Java EE IDE。
版本:Oxygen.2 版本 (4.7.2) 内部版本号: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?
这对我来说没有意义,因为:
- 第三次修改