有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

我使用OS X Yosemite(10.10.2)并有一些java项目,我想在Eclipse中构建它们。有些项目很旧,它们使用Java 5、6和7。起初,我安装了JDK 7和Eclipse Luna。然后我阅读了thisthis线程如何在mac上安装特定的JDK。我使用this脚本安装JDK,并更改了这两行代码,以实现优胜美地兼容性

/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

当我想用Java6或Java7构建项目时,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

但我不认识在约塞米蒂使用这些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>

但这没用

你知道我如何在优胜美地的Eclipse中用java 5构建项目吗

EDIT://问题是JDK 1.5路径引用了CurrentJDK,什么是JDK 1.6。我再次运行JDK1.5和JDK1.6的安装,现在JDK1.5与JDK1.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

在project properties中,我没有收到任何编译器警告,但显然JDK 1.5没有JRE 1.5,因为如果我打开Eclipse preferences Java->;已安装JRE->;在执行环境中,没有任何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


共 (1) 个答案

  1. # 1 楼答案

    我解决了我的问题,只需右键单击Project Explorer中的“Java系统库”,然后选择“属性”。在“执行环境”中,选择了正确的Java版本