In order to support JIA injection for Java 1.4 applications, all dependent .jar files of JIA need to be dynamically loaded to the application. To achieve this, it is necessary to modify the code of the user application. The code modification includes the download list of the JIA .jar files.
Modification of the user application involves adding a new function called jiaInit(String file) inside the application class that includes the main function. The first line in the main function should be a call to this jiaInit function.
The jiaInit function invokes a certain class method (Init method) from a single JIA .jar file (JiaInjection1.4.jar). The file parameter should be the project execution path.
The following example shows how to support JIA injection for the SwingSet application:
public static void JiaInit(String file) throws ClassNotFoundException, { Method method1 = null; try { String fileName = file + "\\Java1.4Support\\ File f = new File(fileName); URLClassLoader urlClassLoader = (URLClassLoader) .getSystemClassLoader(); Class urlClass = URLClassLoader.class; method1 = urlClass.getDeclaredMethod("addURL", new Class[] { URL.class }); method1.setAccessible(true); URL u = f.toURL(); method1.invoke(urlClassLoader, new Object[] { u });
Class lJiaInjectionClass = Class.forName
|
Class[] cArgs = new Class[3]; cArgs[0] = String.class; cArgs[1] = Integer.class; cArgs[2] = Integer.class; Method lInitMethod = lJiaInjectionClass.getDeclaredMethod
Object[] params = new Object[3]; params[0] = new String(file); params[1] = new Integer(4500); params[2] = new Integer(4560);
lInitMethod.setAccessible(true); lInitMethod.invoke(urlClassLoader , params);
} catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); }
} |
public static void main(String[] args) { try { // init from given string JiaInit(“C:\\Projects\\2.2\\Java1.4Support\\ // init using args //JiaInit(args[0]); } catch (SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Create SwingSet on the default monitor SwingSet2 swingset = new SwingSet2(null, GraphicsEnvironment. getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getDefaultConfiguration()); } |