Question

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

Scope:

  • I'm used to build my project with JDK6 and JDK7 within Eclipse Indigo
  • For a specific library I have to use two source code versions (each specific for JDK6 or JDK7)
  • But only one exclusively at a time, because they will throw errors for wrong JDK!

Problem:

  • How to exclusively switch (or activate) a special package / file folder dependent on selected JDK/JRE within Eclipse?
  • There a no kind of C++ macros, which I'm aware of to control source code inclusion during compile time :)

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

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top