0

I need to develop a client which can support any version of server. every time a new server is connected using the client, then appropriate server info is stored on client and the class pat h needs to be set to current server specific class path location. Based on server version class path needs to be set. I am facing setting up this class path dynamically. I always get ClassNotFound Exception. Could you please suggest how do I achieve this.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 1
    More details would be appreciated. Is this new server on another machine? This looks like a deployment problem. What do you use to deploy? – fge Jan 12 '12 at 10:56
  • Are you trying to do what RMI does (Update version of software over the network), or Java WebStart? – Peter Lawrey Jan 12 '12 at 10:58

2 Answers2

0

Classpath can't be set dynamically on runtime. You can do two things here: get familiar with OSGi or write your own classloader. For this particular example writwing own classloader would be easier. What do you keep in server specific classpath? Classes, resources, what? Some details could help.

Piotr Gwiazda
  • 12,080
  • 13
  • 60
  • 91
  • In server specific classpath I will have jars are properties file which are specific to that particular version of server. – user1145302 Jan 12 '12 at 11:33
  • So you need to load clasess from jars on runtime? Try here http://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime – Piotr Gwiazda Jan 12 '12 at 11:40
0

I don't know what exactly are you trying to achieve, but assuming that you have all the needed libraries in your client machine and you are just trying to change the classpath at runtime based on a specific parameter received from the server, then I would give a go to ClassWorlds.

I would try defining a set of class realms using the ClassWorlds' configuration file and client's main class would be implemented using the ClassWorld argument in the main method. Then, the parameter received from the server would be the name of any of those realms. So, just after reading the realm parameter you just need to switch the current thread's classloader to the one created by ClassWorlds for the specific realm.

Alonso Dominguez
  • 7,750
  • 1
  • 27
  • 37