public static void loadNewVersionOfServer() throws Exception { URL[] serverURLs = new URL[] { new URL("file://d:/hotdeploy/server/") }; cl = new URLClassLoader(serverURLs); server = (ServerItf) cl.loadClass("ServerImpl").newInstance(); }
public static void test() throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); loadNewVersionOfServer(); while (true) { System.out.PRint("Enter QUOTE, RELOAD, GC, or QUIT: "); String cmdRead = br.readLine(); String cmd = cmdRead.toUpperCase(); if (cmd.equals("QUIT")) { return; } else if (cmd.equals("QUOTE")) { System.out.println(server.getQuote()); } else if (cmd.equals("RELOAD")) { loadNewVersionOfServer(); } else if (cmd.equals("GC")) { System.gc(); System.runFinalization(); } } }
Enter QUOTE, RELOAD, GC, or QUIT: reload ServerImpl class 12677476 loaded into VM Enter QUOTE, RELOAD, GC, or QUIT: quote you love me Enter QUOTE, RELOAD, GC, or QUIT: