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

anteclipsejavamacososx-yosemite

I use OS X Yosemite (10.10.2) and have some java projects which I want to build in Eclipse. Some projects are old and they are in Java 5, 6 and 7. At first, I installed JDK 7 and Eclipse Luna. Then I read this and this thread how to install specific JDK on mac. I used this script to install JDKs and changed these two lines in order to Yosemite compatibility.

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

by

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

Here is content of my /System/Library/Frameworks/JavaVM.framework/Versions directory

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

Location of JDK 7 is different and the path is /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk

Default Java version is:

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)

Here are installed JDKs in Eclipse preferences

enter image description here

Version 7

enter image description here

Version 6

enter image description here

Version 5

enter image description here

When I want to build projects in java 6 or 7, I don't have any problems with java compiler in Eclipse

enter image description here

enter image description here

But I cannot build some projects in java 5 and probably compiler for java 5 is not set properly

enter image description here

I found this blog post with this problem and solution is

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

but I don't know anybody with working these java versions in Yosemite.

I tried to change Execution Environments in Eclipse preferences

enter image description here

But it didn't help.

Java Build Path in project properties is J2SE-1.5 and I tried to change Execution environment by Alternate JRE

enter image description here

but when I save this settings and open it again J2SE-1.5 is still Execution environment (J2SE-1.5)

Then I tried to add java source and target in build.xml

    <?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>

but it didn't help.

Do you have any idea how can i build projects in java 5 in Eclipse in Yosemite?

EDIT:// The problem was JDK 1.5 path referred to CurrentJDK, what was JDK 1.6. I run installation of JDK 1.5 and 1.6 again and now JDK 1.5 is linked with 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

In project properties I don't get any warnings of compiler, but apparently JDK 1.5 doesn't have JRE 1.5, because if I open Eclipse preferences Java->Installed JREs->Execution Environments, there is not any JRE 1.5

enter image description here

and I cannot build projects in Java 5, because I get errors:

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

This is content of /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0_30 directory

enter image description here

I decided to open new thread

Best Answer

I solved mine with just right-clicking the "Java System Library" in the Project Explorer and chose "Properties". In the "Execution environment" just selected the right Java version.

Related Topic