java - 项目从 Java 6 迁移到 OpenJDK8
问题描述
我从事的项目(工作中)是用 Java 编写的并使用 Java 6。我们正在尝试迁移到 OpenJDK8。我们必须为此使用 Eclipse Indigo(它是项目的一部分)。在阅读了一些以前的线程后,我按照如何迁移的步骤进行操作。我遵循的步骤:
- 要去
Windows -> Preferences -> Java -> Installed JRE's
。在那里,我单击add
并选择了已安装1.8.0
Java 版本的路径。 - 然后我去了
Project -> Properties -> Java Build Path -> Libraries
。在那里我选择JRE System Library
并单击edit
。在Alternate JRE
我选择1.8.0
. - 然后我去了
Build -> External tools configuration -> JRE
。在Separate JRE
我选择的部分1.8.0
。
然后我在打开的Java文件中出现错误(未编译或运行时错误 - 只是eclipse显示红色标记):(第二步后发生错误)
The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
部分代码:
final String arg = getOption(ArgNames.JOB);
if (arg.contains("~~")) {
return arg.split("~~")[1];
} else {
return arg;
}
它说错误是因为arg.contains("~~")
. 我已经阅读了有关该错误的所有先前线程,但他们建议回到旧的 Java 版本(尽管我们想移至 OpenJDK8)。我尝试构建,它实际上没有任何编译错误。我不确定我应该对此感到高兴还是难过,因为我不确定我是否真的用OpenJDK8
. 总结一下,我将尝试提出一些直接的问题:
- 如何验证我使用正确的版本构建它?
- 我应该如何确保所有功能都正常工作
Java 6
? - 如何修复我指出的那个 Eclipse 红色标记错误?
编辑:我单击restart
以重新启动 Eclipse,现在当我尝试构建它时,它失败了。日志文件的第一部分如下所示:
!SESSION 2019-04-18 18:45:36.356 -----------------------------------------------
eclipse.buildId=M20120208-0800
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments: -application org.eclipse.ant.core.antRunner -buildfile tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009//scripts/productBuild/productBuild.xml -Dtimestamp=2010
Command-line arguments: -application org.eclipse.ant.core.antRunner -buildfile tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009//scripts/productBuild/productBuild.xml -Dtimestamp=2010
!ENTRY org.eclipse.osgi 4 0 2019-04-18 18:45:53.567
!MESSAGE Application error
!STACK 1
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.ant.core.AntRunner.run(AntRunner.java:513)
at org.eclipse.ant.core.AntRunner.start(AntRunner.java:600)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/productBuild/productBuild.xml:43: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/build.xml:105: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/templates/headless-build/customTargets.xml:12: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/productBuild/allElements.xml:20: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/genericTargets.xml:118: The following error occurred while executing this line:
tools/eclipse3.7.1-x86_64/plugins/org.eclipse.build_3.7.0.v20111116-2009/scripts/genericTargets.xml:123: The following error occurred while executing this line:
tools/workspace/buildFiles/features/org.eclipse.build.container.feature/build.xml:30: The following error occurred while executing this line:
tools/workspace/buildFiles/features/org.eclipse.build.container.feature/build.xml:16: The following error occurred while executing this line:
tools/workspace/buildFiles/features/com.feature/build.xml:278: The following error occurred while executing this line:
tools/workspace/buildFiles/features/com.feature/build.xml:109: The following error occurred while executing this line:
tools/workspace/buildFiles/plugins/com.testmanagement/build.xml:235: The following error occurred while executing this line:
tools/workspace/buildFiles/plugins/com.testmanagement/build.xml:196: Compile failed; see the compiler error output for details.
我猜有些功能失败了。我知道这个Sun
类在版本 8 中发生了变化。也许是这个原因?
EDIT2:从以前的线程中,我了解到 Eclipse Indiago 不适用于 Java 8。所以我搬到了 Luna。但是现在大多数文件都失败了,因为我的项目使用了 Indiago。一些错误:
The import org.eclipse cannot be resolved
The import org.osgi cannot be resolved
The import junit cannot be resolved
如何解决这些错误?
EDIT3:据我了解,Indigo 不支持 Java 8。所以我搬到了 Luna。但是现在每个插件都失败了。有一堆不存在的路径Windows -> Preferences -> Plug-in Development -> Target Platform -> Running Platform -> edit
。该项目使用 Indigo 而不是 Luna,因此路径不存在:
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.presentations.r21.source_3.2.200.I20100517-1500.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.source_3.7.0.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.log.source_1.0.200.v20110404.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.properties.tabbed.source_3.5.200.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.views.source_3.6.0.v20110928-1505.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.compatibility.source_3.2.100.I20110413-1600.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.source_3.7.1.v20120104-1859.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.ui.workbench.texteditor.source_3.7.0.v20110928-1504.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.configurator.source_3.3.100.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.core.source_3.2.500.v20110330.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.scheduler.source_3.2.300.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.eclipse.update.ui.source_3.2.300.v20100512.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.core.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.integration.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.library.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.hamcrest.text.source_1.1.0.v20090501071000.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.junit.source_3.8.2.v3_8_2_v20100427-1100.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.junit.source_4.8.2.v4_8_2_v20110321-1705.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.mortbay.jetty.server.source_6.1.23.v201012071420.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.mortbay.jetty.util.source_6.1.23.v201012071420.jar
./.metadata/.log:!MESSAGE File does not exist: tools/eclipse/4.4/plugins/org.objectweb.asm.source_3.3.1.v201105211655.jar
它变成了一条长线,对此我很抱歉。如何解决?
解决方案
根据您的评论,您声明您正在使用 Indigo。直到 Luna 才引入 Java 8 支持,尽管 Kepler 可以通过补丁支持它。 https://www.eclipse.org/lists/eclipse.org-committers/msg00948.html
虽然这是一个与 Juno 合作的人的博客: https ://tuhrig.de/java-8-in-eclipse-juno/
这是一个堆栈溢出答案,说他们无法让它与 Indigo 一起使用。 https://stackoverflow.com/a/40053177/3501286
推荐阅读
- kubernetes - 如何使用 Istio 在 Kubernetes 上运行 Mosquitto?
- azure - Azure IoT 中心(事件中心)触发器:找不到有效的帐户信息组合
- android - 在我的项目上启用混淆后在 BroadcastReceiver 中获取 InvalidClassException
- android - 成功构建后无法初始化设计编辑器
- scala - Function1 和 Reader Monad 的关系
- sql - 其他 SQL 脚本执行的 SQL 脚本是否继承父级中为所有客户端设置的系统变量?
- cyber-ark - 如何从 CyberArk Vault 服务器获取 WSUS 服务器详细信息?
- .net-core - MQTTnet:无法使用 TLS 连接:Interop+AppleCrypto+SslException:协议版本错误
- google-sheets - Google Classroom - 为成绩创建电子表格,但不会自动同步
- javascript - 不要设法使用地图从数组中返回不同的行对象