3

I have two versions of a JAR with slightly different APIs (method signatures), one a new version, the other the old version.

I'd like to create an application that can use either (only one at at time though), that can fall-back to the old jar if needed.

For this purpose I have two versions of the relevant class, one that uses the old API, one that uses the new. I can use an environment variable to dictate which JAR is in the classpath, and then the application can use the same variable to decide which class to use.

My problem is, how can I easily build both classes in the same project, given that they are built against different JARs? Any easy solutions?

Chris2048
  • 511
  • 5
  • 19
  • Doesn't look like an 'easy' solution is provided, but you may be able to find some useful information in [this question](http://stackoverflow.com/questions/6105124/java-classpath-classloading-multiple-versions-of-the-same-jar-project). – Henrik Aasted Sørensen Oct 07 '13 at 10:38

1 Answers1

0

Do not show your jars on the classpath. Create two different URLClassLoaders for each jar and load your class manually classLoader1.loadClass or classLoader2.loadClass

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275