Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's up with warnings about runtime not being a 'perfect match' to 'RequiredExecutionEnvironment'?

There is this warning I regularly encounter when working with Java/Eclipse/Maven/OSGi:

The JRE container on the classpath is not a perfect match to the 'JavaSE-1.6' execution environment

I am on a Java 7 JDK. Most project require (rightly so I think) a lower version than that. For example they will require JavaSE-1.6 or JavaSE-1.5. So in their MANIFEST.MF, these projects will have an entry that looks like this (sample taken from a bundle project of mine):

Bundle-RequiredExecutionEnvironment: JavaSE-1.6

This will give me the mentioned warning. Now, I know of two possible ways to 'solve' this warning:

  1. Replace the current runtime environment for the project with a Java 6 runtime
  2. Change the MANIFEST entry to JavaSE-1.7

Both 'solutions' seem completely ludicrous to me. My project does not require JavaSE-1.7. It runs perfectly fine on JavaSE-1.6. Requiring all users of the bundle to have at least Java 7, just because the developer was on Java 7 and did not like the warning seems to me to be the opposite of what you would want. On the other hand, requiring me as a developer to have all versions of Java installed that are listed as required execution environment on projects I work with seems to be almost just as ludicrous. All these projects run perfectly fine on Java 7 so why would I need to have many of them?

Am I completely missing something (in which case I am not the only one), or is this warning really stupid as it is actively promoting developers to set a much higher required execution environment for their projects as would be strictly needed?? Any insight (and hopefully a third way to get rid of this warning) would be greatly appreciated.

like image 282
Stijn de Witt Avatar asked Oct 29 '25 17:10

Stijn de Witt


1 Answers

There are three possible ways to get rid of the warning:

  1. Replace the current runtime environment for the project with a Java 6 runtime (recommended)
  2. Change the MANIFEST entry to JavaSE-1.7
  3. Change the build settings to ignore the warning

Replace the current runtime environment for the project with a Java 6 runtime

This is the recommended solution. What the warning is trying to say is that specifying a minimum required execution environment of Java 6, but then using a Java 7 environment during development is inherently risky as you could write some code that only works in Java 7 and you would not notice this until you deploy to a Java 6 environment and it breaks (thanks to greg-449 and Konstantin Komissarchik for mentioning this in the comments).

Step 1: Add a new Java 6 Runtime environment:

Window -> Preferences -> Java / Installed JREs -> button 'Add...'

Eclipse preferences, Java/Installed JREs

Step 2: Select the newly added JRE as runtime for the project

Poject -> Properties -> Java Build Path

Eclipse Project properties, Java Build Path


Change the MANIFEST entry to JavaSE-1.7

This solution is simple enough. The big downside is that you will be forcing all users of your project to upgrade their Java runtime to whichever version you are using. So it's not so good if you want to support older runtimes as well.


Change the build settings to ignore the warning

Just make Eclipse stop complaining. WARNING: Use with care. Ignoring the warning could make you miss breaking backwards compatibility with older VMs without noticing it.

Window -> Preferences -> Java / Compiler / Building (or the equivalent per-project page if it applies):

Java Building preference page

like image 175
nitind Avatar answered Oct 31 '25 07:10

nitind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!