Domanda

I'm developing a maven plugin that uses the Doclet API (ConfigurationImpl.getInstance() and HtmlDocletWriter.commentTagsToString() for example). This API is contained in tools.jar that comes with the JDK.

On jdk8, these methods don't exist anymore so the plugin breaks.

I'm now looking for a way to make my plugin work with both jdk7 and 8.

I'm thinking about using an interface that offers a stable API and providing different implementations for each JDK. However, I'm not sure how I can switch/load the correct implementation. Mind that everything needs to be packaged in the same jar (the maven plugin).

Any suggestions?

È stato utile?

Soluzione

Create a factory that will give you an instance of your interface. Within the factory you check the java.version system property. If it is >= 8 then you will instantiate the interface implementation for JDK 8, otherwise the one for JDK 7. Those implementation classes must only be loaded in that factory. So you won't get a problem with missing APIs, because the class won't be loaded that depends on that API.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top