How to change workspace JRE in Eclipse - java

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.

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.

java version in not match for eclipse

I had java version 8 previous and my eclipse worked just fine. But now I have java version 7 and I can't open eclipse on my computer. What should I do? please help.
I think there are two options:
Upgrade to Java version 8 (or newer).
If you can't do that, downgrade to a version of eclipse that supports Java 7. eclipse 4.5 (Mars) (or earlier as noted on the linked page), as of eclipse 4.6 (Neon) Java 8 is required.
I feel I should note that newer versions of Java (and eclipse) can still target Java 7 (and many earlier versions).
But now I have java version 7 and I can't open eclipse on my computer. What should I do?
Use versions that work together. When you for example look at your second screen shot, it says something like "requiredJavaVersion=1.8" or so.
In other words: you can't just come in and run eclipse with any version of java.
The other answer gives you the required details.
And a final note here: in case you tried to start eclipse with that older JVM in order to "allow" to ensure that eclipse won't allow "java 8" stuff in a project: that isn't the right way then. Instead: eclipse allows you to "define" JDKs to be used for your project. So you can easily tell eclipse: "I have a Java7 jdk sitting here, please use that for project X".
You do not need to run eclipse itself with a Java7 JVM in order to use a Java7 JDK for an eclipse project!
There will be a file under the Eclipse installation directory named as eclipse.ini.
It will launch the eclipse for that specific jdf and you can change the path to your jdk7.
Hope it helps.
It depends basically on which version of the eclipse you have.
If you have eclipse 4.6(Neon) or the latest version, then you must need a newer JDK version of Java (>=1.8 which you need to download). Or If you want to roll back to an older version of Eclipse then consider downloading eclipse 4.5(Mars).
Or If you have an eclipse version of 4.5(Mars) or older then see in eclipse.ini
-Dosgi.requiredJavaVersion = 1.8 and change it to -Dosgi.requiredJavaVersion = 1.7 which can be found in the folder containing eclipse.exe file.

Updating JDK in Eclipse

I have been having problems with appcompat_v7, someone told me to use Android-21 target. An error with that got me told to use JDK 1.8. I currently have JDK 1.6 installed. How do I switch Eclipse over to use JDK 1.8? I see no place to set the JDK path. The other time this question was asked, the questioner was referred to the JRE settings ... but the JDK is not the JRE, there are two separate paths. How do I get Eclipse to use the new JDK?
Project Menu > Properties menu item > Java Compiler > Compiler Compliance Level
Select your Java version from the pulldown menu. Obviously, you'll need to install Java 1.8 first to get it to show up as an installed version.

Eclipse thinks my JRE is 1.6, when I've migrated to 1.7

I am having a problem with Eclipse Luna after an update. Despite showing in the tree for the project that it is using JRE system library 1.7 the error checking is reporting bugs with a switch using a string that it has a source level below 1.7.
The specific error:
Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
I have tried going into Properties > Build Path and adding and removing the library but this has not fixed the problem.
I moved from the Eclipse packaged with Debain Wheezy which uses the 1.6 JDK and the much older Eclipse 3.8. I am now using CentOS 7 with the 1.7 JDK. The migration has not been as smooth as I hoped. Since there has some big version jumps, I need help getting this new 4.4 version working properly.
Window -> Preferences -> Java Compiler -> set the compiler level to 1.7
Same for Project -> Properties -> Java Compiler -> 1.7
If you can't find that option (by which I mean Compiler 1.7), you must specify the Installed JRE to be JDK 7 too.

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.

Categories