doc*_*doc 6 java eclipse java-11 openjdk-11
我有一个玩具程序,当我尝试使用 Chronicle 导入并编译到语言级别 11 时,该程序仅在 Eclipse 中出现编译错误。该程序在 maven 和 IntelliJ 中编译和运行(使用相同的 maven 和 JDK)。
我拥有的版本是:
这是我的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>testjava11</groupId>
<artifactId>chronicle-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-bom</artifactId>
<version>2.19.199</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
</dependency>
</dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)
这是我的简单测试类:
import net.openhft.chronicle.bytes.BytesMarshallable;
public class App {
public static void main(String[] args) {
System.out.println("BytesMarshallable: " + new BytesMarshallable() {});
}
}
Run Code Online (Sandbox Code Playgroud)
直接使用 maven 运行 exec:java 时的输出是
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< testjava11:chronicle-test >----------------------
[INFO] Building chronicle-test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ chronicle-test ---
[INFO] Deleting C:\Users\eclipse-workspace\chronicle-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ chronicle-test ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ chronicle-test ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\eclipse-workspace\chronicle-test\target\classes
[INFO]
[INFO] --- exec-maven-plugin:3.0.0:java (default-cli) @ chronicle-test ---
BytesMarshallable: App$1@309d6b5b
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.400 s
[INFO] Finished at: 2020-06-11T15:04:53+02:00
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
它在 IntelliJ 中编译,这是我作为 Java 应用程序运行时的输出:
BytesMarshallable: App$1@39fb3ab6
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
然而,在 Eclipse 中 App 类将无法编译。错误出现在导入行并显示:
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
Run Code Online (Sandbox Code Playgroud)
问题面板中还有一条附加消息:
The project was not built since its build path is incomplete.
Cannot find the class file for java.lang.String.
Fix the build path then try building this project
Run Code Online (Sandbox Code Playgroud)
但我不明白我的构建路径中存在什么问题:
此外,我可以看到包资源管理器中存在 java.lang:
(请注意,如果我将语言级别更改为 8,但仍使用 JDK 11,则它将在 Eclipse 中运行。)
我已经检查了明显的问题(构建路径、maven/jdk 路径),一切对我来说都是正确的。为什么在 Eclipse 中出现此错误以及如何修复它?
小智 -1
它与 pom 文件不匹配,因此也在 pom 文件中进行更新。
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)
我已经使用了这两个,然后它对我来说工作得很好。
| 归档时间: |
|
| 查看次数: |
16941 次 |
| 最近记录: |