ChatGPT解决这个技术问题 Extra ChatGPT

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?


J
JasonMArcher

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


This answer is right for Eclipse, but wrong for Maven + Eclipse
This will temporarily fix the problem, until another maven build is run, at which point the JRE version will be reset to the default. See Pascal Thivent's answer to change the default version of the JRE specified in the POM.
All not working. Whenever you do [Alt][F5] to update maven config all such manual tweaks get lots and the warning comes back. See bugs.eclipse.org/bugs/show_bug.cgi?id=376619
Using Eclipse 2020-09, you will need to select "Modulepath" before the "Add Library..." button becomes enabled. This may depend on what version of Java you have installed. Java is in such a state of flux. I am using OpenJDK Corretto-11.0.9.
S
Stevoisiak

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>

I agree, this is the correct answer. Many of the other solutions will temporarily resolve the problem, until another Maven build is run, at which point the JRE will be reset to the default version. Adding this plugin to the POM changes the default JRE version.
Where (full XPATH location) in the pom.xml does this go? Wherever I add it, Maven complains of a malformed pom.
This is the correct answer. The accepted answer is a temporary fix!
I have this in my maven pom.xml and STILL get the warning. Everything seems to work but the warning is still there
N
Niroshan Ratnayake

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.


I have two Workspaces set-up the same way with a JDK 7 but compiling to 1.6 (we'll move over eventually). Machine was hard shut down by good old Windows Update - and the Workspace which was open started showing this and wouldn't be mollified. Thanks for pointing out a work around!
Or another slightly cleaner way: Window -> Preferences -> Java -> Compiler -> Building -> Set "No strictly compatible JRE for execution environment" to "Ignore"
@RedYeti this should work but it's not for me (Eclipse 4.5)
k
krock

In eclipse preferences, go to Java->Installed JREs->Execution Environment and set up a JRE Execution Environment for J2SE-1.4


This will temporarily fix the problem, until another maven build is run, at which point the JRE version will be reset to the default. See Pascal Thivent's answer above to change the default version of the JRE specified in the POM.
No, this is changing the workspace installed JREs and not the one for the specific project (which is what the accepted answer had)
C
Christian

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.


Upvoted because I have a Java 7 project and only Java 8 installed.
N
N..

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>

c
cyberdemon

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
Inasa

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à


S
Stevoisiak

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.


This will temporarily fix the problem, until another maven build is run, at which point the JRE version will be reset to the default. See Pascal Thivent's answer above to change the default version of the JRE specified in the POM.
A
Ankitha J

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.


P
Pragati Chaturvedi

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


How does this differ from btpka3's answer?
A
Akhil

Expand your project in work space>>Right click(JRE System Libraries)>>select properties>>selectworkspace default JRE the above solution sol


This just repeats information covered by btpka3's answer