Eclipse on Mac uses wrong JDK - java

I've got two JDKs on my Mac, 1.8 and OpenJDK 11. I have this line in my .profile:
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
In a terminal, java -version shows it's using 11, and echo $JAVA_HOME also points to 11.
I have set Preferences/Java/Installed JREs to 11. I have set the compliance level to 11 in the compiler config in my pom.
Eclipse, however, shows the "JRE System Library" in my project to be 1.8. When I execute a class in the project, it runs under 1.8.
What gives? Is there a secret setting on the Mac telling Eclipse to use 1.8? Or a secret setting in the Eclipse config?
(I'm using the latest version of Eclipse, 2018-09, fully up-to-date.)
Update: Per #vshcherbinin's comment, the Run Configuration/Java Application/JRE tab says "Project execution environment 'JavaSE-1.8' (Home)". I do not believe I have any project-specific settings. I deleted the .project, .classpath, and .settings in the project and re-imported the basic Maven project. Not sure how to make the project execution environment default to 11.

Related

exec-maven-plugin Java version different from maven-compiler-plugin Java version in NetBeans project

I start up the NetBeans IDE 12.0 with a system environment JAVA_HOME (1.8) lower than what the IDE uses (14). The IDE output window of Maven execution seems to show that the project is run with JAVA_HOME for JDK 14, running project files this way.
But the exec-maven-plugin fails with java.lang.UnsupportedClassVersionError: com/mycompany/Start has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
This seems to indicate that Maven runs under 1.8 in the IDE, ignoring the IDE's own override setting of JAVA_HOME of 14. It uses the JDK as set in JAVA_HOME, because if I set JAVA_HOME to 14.0 before IDE startup then it works.
I am looking for the correct way, the right places, to set the JDK for any project specifically, regardless of the JAVA_HOME setting that is active when the IDE starts.
My case can be reproduced by running the IDE 12.0 with JDK 14.0 installed, but with JAVA_HOME set to 1.8. before IDE startup. I use the Maven project generated from the command at https://wicket.apache.org/start/quickstart.html - all set to defaults. The file to run is Start.java.
This is important to me because I must open many different projects with different JDKs so it is not practical to re-start the IDE with different JAVA_HOME settings each time. As it is, it appears that my setting is poorly defined - I must be missing something.
I should add that in the project properties, I have set the Build|Compile|Java Platform to JDK 14 (Default) as expected.
I have filed a NetBeans Issue
For maven, if you want the byte code of your project to be 1.8, try just setting variables used by the compiler plugin even if you're using a newer JDK.
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
If you want a different java install completely, then you might want to look into the toolchains. But I'd only go this route if the above doesn't meet your needs.
https://maven.apache.org/guides/mini/guide-using-toolchains.html
I am not familiar with NetBeans but hopefully it will read the compiler level for maven.

Choose Gradle JDK in IntelliJ

My system JAVA_HOME and PATH are pointing to JDK 7, but I want to use JDK 8 in project opened in IntelliJ. I changes settings in Project Structure and it works great in IDE, but unfortunately Gradle build run from IDE still uses JDK 7. How can I specify Gradle JDK in IntelliJ 13.0?

how to configure JDK as the default JVM in my workspace

Im trying to create a new grails project using the IDE GGTS (groovy and grails tool suite )
but it says that grails needs a JDK and JRE is not enough , I already installed JDK 1.7 and added the JAVA_HOME to the path
i also copied the grails folder and added a GRAILS_HOME to the path
in GGTS :
i tried In Window>Preferences>Java>Installed JREs to check JDK1.7.0_51
and
In Window>Preferences>Java>Installed JREs>Execution Environments I choosed JavaSE-1.7 and checked JDK1.7.0_51[perfect match]
the JDK installed is 64 bits and My PC is windows 8 64 bits
but the error persists
We have to make sure that the Java run time of our eclipse IDE points to a JDK instead of a JRE. Here are the steps:
Go to Window->Preferences
Edit Installed JRE if it is pointing to a JRE installation
Change it to the JDK installation directory. It is better if you also change the name

IBM Worklight - .war builder using wrong Java version

I've setup Worklight Studio to use JDK 1.6 in my Worklight project.
I also changed the "compilation compliance level" to 1.6.
Eclipse is started with jdk/jre 1.6.
Despite all of this, the war is generated with Java 1.7!!!
My JAVA_HOME and JRE_HOME variables are also set to my JDK/JRE 1.6.
I'm operating under Windows 7 (64 bit).
How can I tell Worklight to build the war with jdk 1.6, not the default Windows one?
In Eclipse, navigate to Window > Preferences > Java > Installed JREs. Make sure JRE v6 is the version that is to be used (also try to remove and re-add it, maybe it's some stuck configuration option...).
This is the JRE version Eclipse will use to generate the .war file in your Worklight project.
For good measure, delete your existing .war file before generating a new one after changing the above.

How to change workspace JRE in Eclipse

While creating new Java project in Eclipse I got following warning "The current workspace uses 1.4 JRE..."
I have JRE7 on my system. I have added following lines in eclipse.ini
-vm
C:\Java\jre7\bin\javaw.exe
I have added JRE7 to Installed JREs through Windows -> Preferences-> Installed JREs.
Still under Compiler tab I can see only compiler compliance level till 6.
How can I change workspace JRE to JRE 7 ?
Java 7 support is only available since Eclipse Indigo SR1 (released about a month ago). So, upgrade Eclipse.
I also have jre7, and it really doesn't matter if it only says that is compliant with 1.6, because the project will look for the java compiler specified by the jre/jdk used in the project.
I also recommend you use the jdk instead of the jre, and set the environment variable JAVA_HOME, there's lots of tutorials on this in Google.
The issue where it is compiling with 1.4 but the workspace Preferences Compiler setting is 1.6 seems to be the issue described in this bug:
Bug 499675 - Global compiler settings ignored after restarting, defaults to 1.4 even though 1.8 displayed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=499675
where the workaround is to change the workspace setting to a different version number and then back to 1.6. That would enable the workspace to compile with 1.6.
To compile with 1.7 you'd need to upgrade eclipse as in BalusC's answer.

Categories