Hi There !
I am in a situation and I need some help, if anyone can help me.
I have two tools to work with different version of a server application. Now, the admin wants to have only one tool to work with both server app.
The problem is that the server app has a jar file with the API to be used to access it. One jar for each version.
Inside those jars files I have the same package and the same class ! But the implementation is diferent. So I will need to access one jar when accessing the old server app and another jar to access the new server app.
I have no idea how to do it.
I search arround google and I found that I can load a class at runtime and then with Reflection call its methods.
I made a test app (simple, just 2 different jars with same package and class name just printing a Hello World and Bye World) and it worked very well.
But when I tried to apply this to my code, I realize that one class need the reference of the other class...
For example, I have a class named Server and other called ServerStatus.
The Server class do the connection to the server and the ServerStatus get some server information. But the method that give me this information has a argument asking for an object of Server... like this:
Server serv = new Server();
serv.connect();
ServerStatus servStat = new ServerStatus();
servStat.getServerStatus(serv);
I tried to do this with reflection but in the part that I need to invoke the method getServerStatus, I do not have the name of the class that is the argument (in this case Server).
Something like this:
Method m = serverClass.getMethod("getServerStatus", new Class[] {?????.class});
result = (Boolean)m.invoke(server, new Object[] {serverStatus});
Do you have any ideiias to resolve this ?
Or something different from reflection to access two different implementations with same package and class name ?
If you need any other information, please ask me..
Thank you so much !
Regards,
Thiago