eclipsecompilationdependenciesjava-7jdk6

Eclipse: Howto organize JDK or JRE (JDK6 or JDK7) dependent sources?


Maybe I only missed the right keywords / concept how to describe my problem.

Scope:

Problem:

Is there an option available in Eclipse without bypassing to ANT or other scripted build environments?


Solution

  • You would do this by using plugins and setting the execution environment of the plugins to depends on the desired JRE. However, the execution environment checking will enable your plugin when the execution environment satisfies (or is greater than what's required. So specifically I recommend using a fragment so that the JRE7 code "overrides" the JRE6 code.

    The way to this is to have your JRE6 code be in your base plugin. But have the classpath of your plugin refer to a non-existent JAR file first, then then "." (to get the code in the base plugin). Then have a JRE7 fragment that provides the JAR file with the classes to replace your JRE6 classes. (It's otherwise not possible to have a fragment override a plugin in OSGi).

    I think this should also work correctly when test running your code using PDE in the IDE.