0

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?

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
spex66
  • 186
  • 2
  • 10

1 Answers1

0

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.

Francis Upton IV
  • 19,322
  • 3
  • 53
  • 57
  • I don't think the OP is talking about plugin development here. I think they are talking about a normal project with multiple targets (i.e. JDK6 and JDK7). – Matthew Farwell Dec 18 '11 at 19:35
  • 1
    I think even with normal projects you will need to split your code because a project will be targeted to a particular JRE version. In that case of non-plugins, you would setup the Libraries in the Java Build Bath (in the Build configuration) to point to the desired JRE. – Francis Upton IV Dec 18 '11 at 19:42