java - 构建路径指定执行环境J2SE-1.5。工作区中没有安装与此环境严格兼容的 JRE

标签 java eclipse macos ant osx-yosemite

我使用 OS X Yosemite (10.10.2) 并且有一些我想在 Eclipse 中构建的 java 项目。有些项目很旧,它们使用 Java 5、6 和 7。首先,我安装了 JDK 7 和 Eclipse Luna。然后我读到thisthis线程如何在 Mac 上安装特定的 JDK。我用过this安装 JDK 的脚本并更改了这两行以兼容 Yosemite。

/usr/libexec/PlistBuddy -c "Set :JavaVM:JVMMaximumFrameworkVersion 14.*.*" ./Resources/Info.plist
/usr/libexec/PlistBuddy -c "Set :JavaVM:JVMMaximumSystemVersion "$osx_version".*" ./Resources/Info.plist

/usr/libexec/PlistBuddy -c "Delete :JavaVM:JVMMaximumFrameworkVersion" ./Resources/Info.plist
/usr/libexec/PlistBuddy -c "Delete :JavaVM:JVMMaximumSystemVersion" ./Resources/Info.plist

这是我的 /System/Library/Frameworks/JavaVM.framework/Versions 目录的内容

lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.5 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.5.0 -> CurrentJDK
drwxr-xr-x  9 root  wheel  306  8 apr 14:32 1.5.0_30
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.6.0 -> CurrentJDK
drwxr-xr-x  7 root  wheel  238  8 apr 14:36 A
lrwxr-xr-x  1 root  wheel    1  8 apr 14:36 Current -> A
lrwxr-xr-x  1 root  wheel   59  8 apr 14:36 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents

JDK 7的位置不同,路径为/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk

默认 Java 版本是:

AND:bin andr-work$ java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

以下是 Eclipse 首选项中已安装的 JDK

enter image description here

版本 7

enter image description here

版本 6

enter image description here

版本 5

enter image description here

当我想在 java 6 或 7 中构建项目时,Eclipse 中的 java 编译器没有任何问题

enter image description here

enter image description here

但是我无法在 java 5 中构建一些项目,可能 java 5 的编译器设置不正确

enter image description here

我找到了this有关此问题和解决方案的博客文章是

...replace the "A" subdirectory with files from someone else's Mac

但我不知道有人在 Yosemite 中使用这些 java 版本。

我尝试在 Eclipse 首选项中更改执行环境

enter image description here

但这并没有帮助。

项目属性中的Java构建路径J2SE-1.5,我尝试通过备用JRE更改执行环境>

enter image description here

但是当我保存此设置并再次打开它时J2SE-1.5仍然是执行环境(J2SE-1.5)

然后我尝试在 build.xml 中添加 java sourcetarget

    <?xml version="1.0"?>
<project name="build" default="jar">
    <description>
            A build script
    </description>

    <property name="ant.build.javac.source" value="1.5"/>
    <property name="ant.build.javac.target" value="1.5"/>

    <property name="dist.jar" value="ci-ons.jar"></property>
    <property name="dist.folder" value="dist"></property>
    <property name="src.folder" value="src"/>
    <property name="classes.folder" value="bin"/>

</project>

但这并没有帮助。

您知道如何在 Yosemite 的 Eclipse 中使用 java 5 构建项目吗?

编辑://问题是 JDK 1.5 路径引用了 CurrentJDK,而 JDK 1.6 是什么。我再次运行 JDK 1.5 和 1.6 的安装,现在 JDK 1.5 已与 JDK 1.5 链接

lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.4 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.4.2 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  9 apr 11:01 1.5 -> ./1.5.0_30
lrwxr-xr-x  1 root  wheel   10  9 apr 11:01 1.5.0 -> ./1.5.0_30
drwxr-xr-x  9 root  wheel  306  9 apr 11:01 1.5.0_30
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.6 -> CurrentJDK
lrwxr-xr-x  1 root  wheel   10  8 apr 14:36 1.6.0 -> CurrentJDK
drwxr-xr-x  7 root  wheel  238  8 apr 14:36 A
lrwxr-xr-x  1 root  wheel    1  8 apr 14:36 Current -> A

在项目属性中,我没有收到任何编译器警告,但显然 JDK 1.5 没有 JRE 1.5,因为如果我打开 Eclipse 首选项 Java->Installed JREs->Execution Environments,则没有任何 JRE 1.5

enter image description here

并且我无法在 Java 5 中构建项目,因为出现错误:

Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment.

这是/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30目录的内容

enter image description here

我决定打开新的thread

最佳答案

我只需右键单击项目资源管理器中的“Java System Library”并选择“属性”即可解决我的问题。在“执行环境”中只需选择正确的Java版本。

关于java - 构建路径指定执行环境J2SE-1.5。工作区中没有安装与此环境严格兼容的 JRE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29523955/

相关文章:

java - 帮助匹配两个类之间的字段

java - 计数数组的行为

java - 在 Eclipse 启动时启动 Tomcat?

Android:自定义操作栏主题错误 -(未找到匹配的资源......)

java - 黑莓 Eclipse 显示设备文件夹

c - 如何在 Mac 上从 C 访问 macOS API 调用?

java - 嵌套 while 循环的大 O 符号解释

java - 如何类型安全地检查 boolean 值是否相等?

objective-c - 隐藏在 Lion 中的滚动条。如果人们不使用触控板,他们如何水平滚动?

ios - 为什么 NSDictionary 实现为类簇?