I use the following method to call a class inside a jar file:
invokeClass("path.to.classfile", new String[] {}); public static void invokeClass(String name, String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, MalformedURLException { File f = new File(System.getProperty("user.home") + File.separator + ".myapplication"+File.separator+"myjar.jar"); URLClassLoader u = new URLClassLoader(new URL[]{f.toURI().toURL()}); Class c = u.loadClass(name); Method m = c.getMethod("main", new Class[] { args.getClass() }); m.setAccessible(true); int mods = m.getModifiers(); if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) { throw new NoSuchMethodException("main"); } try { m.invoke(null, new Object[] { args }); } catch (IllegalAccessException e) { } }
Is it possible to call this in a separate process? So, the running application and the new called application have nothing in common?
Situation: you are running program a (client update program). From client a, you run program b (client)
With the current code, project a and all instances of project b have the same heap space. I am trying to reach a state where all instances of project b are autonomous and don't care if project A is complete or not.
source share