javaimportjacorb

Dealing with jar package structure changes


I'm in a bit of a predicament and I'm looking for some help on how to solve it. I have some source code that imports various classes from a jar file created from idls. Now I've been given a new version of this idl jar that has a different package structure which breaks all of my old import statements. I can't modify the import statements so I'm trying to see if there is a way around this. Any ideas?

Basically I'm being asked to make the current source code work with both the new and old versions of the jar, preferably without modifying the code. I don't think it's possible but I'm hoping I'm wrong.


Solution

  • Here is one thing you could do: recreate all the old classes and make them match with the new ones. For example, if you had a.Foo, and it is now b.foo, you can have:

    package a;
    public class Foo {
        b.Foo foo;
        public void method() {
            foo.method();
        }
    }
    
    package b;
    public class Foo {
        public void method() {
            // Your new code...
        }
    }
    

    This is a bit of a pain, but I'm afraid it is the price to pay to have backwards compatibility.

    Another solution, if you class structure allows it, would be o have a.Foo inherit b.foo, so you don't have to create all the delegate methods. But depending on your project that might not work.

    Hope this helps.