Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 503
John29 Avatar asked May 01 '18 12:05

John29


1 Answers

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.

like image 103
crizzis Avatar answered Sep 21 '22 14:09

crizzis