java library versioning

Hi

I have two versions of one library (jar file) and I need to support exclusively both of them in my code (firts version or second). Both versions have different APIs (e.g. method names, parameters ...). Since the Java doesn't have a preprocessor, I can't just use something like #if ver = 123. The only solution in my mind now is to create two versions of every class file which uses any of the function from that library, or just one class like an "interfare" or a driver with two versions. Is there a better solution?

Thanks in advance

Martin

[573 byte] By [EpiMartin] at [2007-9-30 22:31:15]
# 1

Regardless of the jar names, if the contents of the jars have duplicate names, then the one encountered first on the classpath will be the one used, to the exclusion of the other.

If the contents of the jars have different names, then there isn't a problem.

I guess that I don't understand the problem.

ChuckBing at 2007-7-7 12:54:32 > top of Java-index,Administration Tools,Sun Connection...
# 2

OK. I'll try to explain the problem in an example.

Imagine that you use in your java application a library_ver1.jar which provides a class you use. That class has methods:

method1(param11, param12, param13)

method2(param21, param22)

...

Now, the customer comes and will tell you that your application has to support library_ver2 too. That library has the same class, but method names and / or parameters are different:

method1_foo(param11, param12, param13)

method2(param21, param23, param22)

So, it would be the best, if I could use in my java application something like in C:

#if VERSION == 1

result1 = method1(param11, param12,param13);

result2 = method2(param21, param22);

#else

result1 = method1_foo(param11, param12,param13);

result2 = method2(param21, null, param22);

#endif

I know java has no preprocessor. But what is the best solution to achieve the desired effect?

Thanks in advance

EpiMartin at 2007-7-7 12:54:32 > top of Java-index,Administration Tools,Sun Connection...
# 3

So you've got what amount to overloaded methods, but some of them are in a .class file in one jar, and the rest are in a .class file (with the same name) in another jar.

Short of combining the jars, and merging the same-named classes, I don't see a solution.

But maybe someone else will have one. Best luck.

ChuckBing at 2007-7-7 12:54:32 > top of Java-index,Administration Tools,Sun Connection...