Eclipse Default JRE Preference Installed JRE Not Working - java

I went to the Preference of Eclipse and changed the default JRE to the Java SE 8, and also changed the Compiler settings of Eclipse to be 1.8 JDK compliance. I even removed the other JREs.
However, when I import a project, as you can see from the Project Explorer, the project name is "SpringService", somehow the JRE System Library is JavaSE-1.6 and they are still using 1.6 as default!
Can anyone tell me what I did wrong? Otherwise every new project I have to manually go to the properties and change it manually! Hate it!
This post might be relevant to enter link description here SO question.

When you set your Installed JREs preference, you want to select the root directory of a full Java Development Kit installation, not just a bare JRE installation. Eclipse needs access to the supporting libraries that are bundled with a full JDK, but absent from a base JRE install.
Also, if you are importing a project, do you mean that you are importing an existing, pre-configured Eclipse project? Or just the directory structure that contains the source code? If you are importing an existing Eclipse project, it may have already been set up with project-specific settings (it's hard to give advice with being able to poke around in the settings).

Check the plugin section in the pom.xml to see if it contains the following entry.
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
This will overwrite the default preference. A lot of maven project archetype uses 1.6. Just change them to 1.8 and do a Maven->Update Project.

U can you 'Build Path' on the project ,then remove the jre1.6, add the user libiary .

Related

Eclipse project: Maven Eclipse Plugin set wrong JRE class path container

I have an Eclipse Mars 2 Java8, Maven 3.5.4 based workspace.
I build the project files with mvn eclipse:clean eclipse:eclipse, and watch the following maven output:
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-**1.7**
The default JRE for the workspace isn't Java 7, it is Java 8, like you can see looking at the following Eclipse config file:
<workspace>\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.launching.prefs.
that contains the following data:
org.eclipse.jdt.launching.PREF_VM_XML=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?>
<vmSettings defaultVM\="57,org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType13,1538040823497*">
<vmType id\="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType">
<vm id\="1431694854640" name\="jdk1.7.0_40" path\="C\:\\Program Files\\Java\\jdk1.7.0_40"/>
<vm id\="1447417000092" name\="jdk1.6.0_45" path\="C\:\\Program Files\\Java\\jdk1.6.0_45"/>
<vm id\="1538040823497" name\="jdk1.8.0_65" path\="C\:\\Program Files\\Java\\jdk1.8.0_65"/>
</vmType>
</vmSettings>
As you may notice by looking at the above configuration, the default VM has the vm id "1538040823497", which is named jdk1.8.0_65, and resides in C\:\\Program Files\\Java\\jdk1.8.0_65.
This VM is correctly registered as Workspace Default in Eclipse Preferences, Java/Installed JREs, is marked as a "perfect match" within the Execution Environment JAVASE-1.8.
I cannot see anything why Maven Eclipse Plugin considers
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7 as the correct choice, and not JAVASE-1.8.
I already deleted all JREs and registered them newly.
Now there's exactly one 1.6, 1.7 and 1.8 Environment, each with a "perfect match", and 1.8 is checked as default (as you can see above).
I have to manually correct the project each time I generated it (Edit Build Path, change JRE library from 7 to 8), since all files using Java 8 features like streams or lambda functions signal compiler errors unless I assign the correct JRE manually.
I already tried and manipulate org.eclipse.jdt.launching.prefs, redefine all JREs, pray, curse or ask an Ouija board, to no avail, always Java 7 is assigned by the eclipse plugin (version 2.10, by the way).
Any ideas, anyone?
In your pom file, try to use this:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
You may also reference this link:
https://dzone.com/articles/maven-eclipse-and-java-9
Or if all fails, try eclipse oxygen, a newer version (not the newest release but much better than Mars IMO) that has Maven Integration plugin pre-installed, all you need is to add a m2e-connector plugin.

Avoid the "no JREs installed in the workspace that are strictly compatible" warning in Eclipse for multiple Java versions

I know that there are already a lot of questions about this warning, but my question is a little bit different. I understand that I can use this configuration in my pom.xml to fix it
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
This gets rid of the warning, but only if I have Java 7 installed and configured in Eclipse. If for example I only have Java 8, I still see the warning unless I change the version in the configuration above to 1.8:
Build path specifies execution environment JavaSE-1.7. There are no
JREs installed in the workspace that are strictly compatible with this
environment.
My project is compatible with Java 7, 8, 9 and 10. What I want to achieve is to avoid this warning if any of these versions of Java is installed without changing the version in my pom.xml to match the currently installed Java version every time. Something to tell Eclipse that Java 7 or anything above is good.
The project still compiles and works fine with the warning, it's just distracting as it marks the project as having issues. I know that I can hide this type of warnings in Eclipse settings, but is there a way to get rid of it by only using some configuration in pom.xml?
Eclipse uses the value <target>1.7</target> to decide which execution environment to include in the build path, as part of its Maven integration.
The execution environments are mapped to JREs installed in Eclipse (i.e. referenced in Preferences > Java > Installed JREs).
The mapping itself is configured in Preferences > Java > Installed JREs > Runtime Environments. Eclipse will automatically match an execution environment (e.g. JavaSE-1.7) to an installed JRE (e.g. jdk1.7.0_80). If there is no exact match for the execution environment specified in your project, it will give you a warning like the one you're getting.
Therefore, to get rid of the warning, you must either:
Install the Java version that is an exact match for your <target> (i.e. jdk1.7) and add it under Preferences > Java > Installed JREs > Runtime Environments
Configure the Java version in your pom to one for which there is an exact match
My project is compatible with Java 7, 8, 9 and 10. What I want to achieve is to avoid this warning if any of these versions of Java is installed
When configuring the execution environment to use, Eclipse only cares for the <target> value. You need to make sure that there is a JRE installed in Eclipse whose version is a perfect match for the value of that property. Otherwise, the warning will not go away, period.
I don't have the intention to target some specific version, the default target would work fine for me.
No, it wouldn't, because the default target is 1.5. Target configuration is a non-optional configuration property, there is no 'target everything' option.
You could remove the Maven-configured execution environment from the build path and add a JRE directly (project properties > Java Build Path > Libraries > Add library... > JRE System Library > Alternate JRE). This will also make the warning go away, but it will be back as soon as you run Maven project update. Such a configuration shouldn't really be used, as it ties your project to a specific installation of Java on your machine.

IntelliJ imports project from POM using wrong JDK version

We have a Maven based Android build, and we just made the switch from JDK 6 to 7.
This came with its share of IntelliJ problems though. What happens is that every time it detects a change in the POM, and reimports/refreshes the project, it returns to selecting the old "Module SDK", the one that's configured to use Java 6:
Even if I manually delete these SDKs from the "Platform Settings" dialog, they keep reappearing as "Maven Android API 19 Platform (N)" where N is the number used to disambiguate it from all the other (identical) SDKs.
I should mention that we do specify in the POM that Java 7 is targeted. I tried to set both the compiler plugin language level, and the maven.compiler.* properties (not sure if that accomplishes the same thing or not), without luck:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
shouldn't IntelliJ pick that up and always configure the project to use a Java 7 SDK? Am I missing something?
I noticed that the problem disappears when I remove any references to 1.6 SDKs entirely in IntelliJ. Not surprising I guess, but also not viable since I have other projects that still rely on the presence of a Java 6 SDK.
I encountered a very similar issue with Maven projects I'd created using IntelliJ (version 14.x in my case). I'd configured IntelliJ to use JDK 8 in the Project Settings but the IDE continued to highlight issues in my code (e.g. complaining about the usage of #Override).
It turns out that the Maven Settings take precedence here, which in my case defaulted to JDK 1.5 (hence the IDE redlines). Changing the settings here does resolve the issue, but only temporarily because they revert back whenever the Maven projects are reimported, or when IntelliJ is restarted.
The permanent fix is to explicitly declared the JDK version in your Maven pom file, as explained in these items.
stop IntelliJ IDEA to switch java language level everytime the pom is reloaded (or change the default project language level) by #vikingsteve
IDEA: javac: source release 1.7 requires target release 1.7 by #bacchus
Here's what they've said you need to add to your pom.xml file.
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
These settings get reflected in the Maven Settings in the IDE and resolved the issue for me.
It will pick up the jdk that you choose in project structure please change it there.
File > project structure > project setting > project > project sdk choose 1.7.
If 1.7 is not present go to
File > project structure > Platform setting > SDKs addd 1.7 there.
It's also important to note that you need to change the runner (jdk level) of your maven.
Maven > Runner > JRE

How do I change the IntelliJ IDEA default JDK?

I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA informs me that the Language Level Changed and that Language level changes will take effect on project reload, and then prompts to reload the project. This is annoying because I always use the same JDK version.
How do I change the default JDK that IntelliJ IDEA uses, so that I don't have to reload my project every time I import a new project?
This setting is changed in the "Structure for New Projects" dialog. Navigate to "File" -> "New Projects Setup" -> "Structure..."
Next, modify the "Project SDK" and "Project Language Level" as appropriate.
Previous versions of IntelliJ IDEA had this setting in "File" -> "Other Settings" -> "Default Project Structure...".
IntelliJ IDEA 12 had this setting in "Template Project Structure..." instead of "Default Project Structure..."
Download and unpack a JDK archive file (.tar.gz) and add it as a SDK in the 'Project Structure' dialog box ( Ctrl+Alt+Shift+S )
click on the gif to enlarge
Also make sure to set an appropriate 'Project language level'. I forgot to do that when creating the GIF.
Project Structure > Project > Project language level
For Java 8 set it to 8, for Java 9 set it to 9, and so on.
I am using IntelliJ IDEA 14.0.3, and I also have same question. Choose menu File \ Other Settings \ Default Project Structure...
Choose Project tab, section Project language level, choose level from dropdown list, this setting is default for all new project.
I have found out that in recent versions of IntelliJ IDEA requires Java 1.8 but is not configured by default.
We can change the path or configure from Project Settings > Project > Project SDK
here we can edit or add the JDK´s path.
(in my case the path is located in C:\Program Files\Java\jdk1.8.0_102)
Change JDK version to 1.8
Language level File -> project Structure -> Modules -> Sources -> Language level -> 8-Lambdas, type annotations etc.
Project SDk File -> project Structure -> Project 1.8
Java compiler File -> Settings -> Build, Executions, Deployment -> Compiler -> Java compiler
One other place worth checking: Look in the pom.xml for your project, if you are using Maven compiler plugin, at the source/target config and make sure it is the desired version of Java. I found that I had 1.7 in the following; I changed it to 1.8 and then everything compiled correctly in IntelliJ.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
The above responses were very useful, but after all settings, the project was running with the wrong version. Finally, I noticed that it can be also configured in the Dependencies window.
Idea 2018.1.3 File -> Project Structure -> Modules -> Sources and Dependencies.
To change the JDK version of the Intellij-IDE himself:
Start the IDE -> Help -> Find Action
than type:
Switch Boot JDK
or (depend on your version)
Switch IDE boot JDK
For latest version intellij, to set default jdk/sdk for new projects go to
Configure->Structure for New Projects -> Project Settings -> Project SDK
I am using IntelliJ 2020.3.1 and the File > Other Settings... menu option has disappeared. I went to Settings in the usual way and searched for "jdk". Under Build, Execution, Deployment > Build Tools > Maven > Importing I found the the setting that will solve my specific issue:
JDK for importer.
On my linux machine I use a script like this:
export IDEA_JDK=/opt/jdk14
/idea-IC/bin/idea.sh

Warning - Build path specifies execution environment J2SE-1.4

I create a Maven project in Eclipse Helios. It works fine for a day, but then this warning shows up:
Build path specifies execution environment J2SE-1.4. There are no JREs installed in the workspace that are strictly compatible with this environment.
Since this message, the project stopped compiling and debugging. Does anyone have solution for this problem?
In Eclipse from your project:
Right-click on your project
Click Properties
Java build path: Libraries; Remove the "JRE System Library[J2SE 1.4]"
Click Add Library -> JRE System Library
Select the new "Execution Environment" or Workspace default JRE
Whether you're using the maven eclipse plugin or m2eclipse, Eclipse's project configuration is derived from the POM, so you need to configure the maven compiler plugin for 1.6 (it defaults to 1.4).
Add the following to your project's pom.xml, save, then go to your Eclipse project and select Properties > Maven > Update Project Configuration:
<project>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The above solutions fix the project or work around the problem in some way. Sometimes you just don't want to fix the project and just hide the warning instead.
To do that, configure the contents of the warning panel and make sure to toggle-off the "build path"->"JRE System Path Problem" category. The UI for this dialog is a bit complex/weird/usability challenged so you might have to fiddle with a few of the options to make it do what you want.
In eclipse preferences, go to Java->Installed JREs->Execution Environment and set up a JRE Execution Environment for J2SE-1.4
The actual cause of this warning is that you have configured your project to run with an earlier JRE version then you have installed. Generally this occurs whenever you use old projects with newer JREs.
This will likely cause no trouble at all. But if you want to be really on the save side, you should install the correct, old JDK. You can find them here: http://www.oracle.com/technetwork/java/archive-139210.html
If you then restart eclipse you can go into Window > Preferences > Java > Installed JREs > Execution Environments and set for in your case J2SE-1.4 the [perfect match] as eclipse calls it.
If you have Java 1.8 then
You need this xml part in pom.xml and update project.
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
the correct procedure to resolve this warning, as other people write, is to go inside your project Properties and click on Java Build Path located on the left. Now you will find inside the Libraries Window the J2SE 1.5, double click on this one and a new window will give you the possibility to choose the correct Excecution Environment. Now select your version and the warning will disappear.
I met the same warning in STS (Spring Tool Suite), if it may help someone somehow.
This is the source https://www.baeldung.com/eclipse-change-java-version, and here's a summary of it :
Warning :
build path specifies execution environment javase-11. there are no jres installed in the workspace that are strictly compatible with this environment.
Environment :
Ubuntu 20.04 (with default OpenJDK11)
STS 4
To solve the warning :
Change the JRE of the workspace of STS (By default, STS uses the JRE embedded in its plugins) :
Window>Preferences>Installed JREs>Add>Standard VM>Directory (browse to your openjdk folder, in my case /usr/lib/jvm/java-11-openjdk-amd64)>Finish)
Check the new JRE, then Apply and close
Now configure the spring-boot project to use the newly added JRE :
Right click on the project > properties > Java Build Path > in Libraries tab > Remove the old JRE, then in Modulepath Add Library > JRE System Library > Environments (choose JavaSE-11, make sure to check it on the right panel, mentionned "perfect-match"), Apply and Close
And voilà
Did you setup your project to be compiled with 1.4 compliance? If so, do what krock said. Or to be more exact you need to select the J2SE-1.4 execution environment and check one of the installed JRE that you want to use in 1.4 compliance mode; most likely you'll have a 1.6 JRE installed, just check that one. Or install a 1.4 JRE if you have a setup kit, and use that one.
Otherwise go to your Eclipse preferences, Java -> Compiler and check if the compliance is set to 1.4. If it is change it back to 1.6. If it's not go to the project properties, and check if it has project specific settings. Go to Java Compiler, and uncheck that if you want to use the general eclipse preferences. Or set the project specific settings to 1.6, so that it's always 1.6 regardless of eclipse preferences.
Just change the version in Window-> Preferences-> Java -> Installed JREs. Check the installed JREs list.
Then, Right-click on your project -> properties -> Java build path -> libraries. Change the "JRE System Library" to the version in "installed JREs".
The warning will be gone.
I was getting project warning as "Build path specifies execution environment J2SE-1.5. There are no JREs installed in the workspace that are strictly compatible with this environment".
I removed the J2SE1.5 library and added new JRE System Library which resolved my problem
Expand your project in work space>>Right click(JRE System Libraries)>>select properties>>selectworkspace default JRE
the above solution sol

Categories

Resources