Changeset 265
- Timestamp:
- 11/30/11 13:46:47 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JFCMonitor/src/de/ugoe/cs/eventbench/jfcmonitor/JarLauncher.java
r264 r265 12 12 import java.util.jar.Manifest; 13 13 14 /** 15 * <p> 16 * Class that launches an executable Jar-file in the same thread and VM where 17 * the JarLauncher instance is created. The requirements on the Jar file are: 18 * <li>Must contain a MANIFEST.</li> 19 * <li>The MANIFEST must define the main-class of the application ("Main-Class" 20 * entry).</li> 21 * <li>The MANIFEST must define the classpath of the application ("Class-Path" 22 * entry).</li> 23 * </p> 24 * 25 * @author Steffen Herbold 26 * @version 1.0 27 */ 14 28 public class JarLauncher { 15 29 16 String workingDir = System.getProperty("user.dir") + "/"; 17 String jarfile; 18 String[] args; 19 20 String[] classPath = new String[] {}; 21 String mainClassName = ""; 22 ClassLoader costumClassLoader; 23 24 public class JarLaunchException extends Exception { 25 30 /** 31 * <p> 32 * Name of the Jar file to be executed. 33 * </p> 34 */ 35 private String jarfile; 36 37 /** 38 * <p> 39 * Arguments for launching the Jar file. 40 * </p> 41 */ 42 private String[] args; 43 44 /** 45 * <p> 46 * Helper variable with the path to the working directory. 47 * </p> 48 */ 49 final String workingDir = System.getProperty("user.dir") + "/"; 50 51 /** 52 * <p> 53 * Internal variable used to store the classpath extracted from the Jar 54 * file's MANIFEST. 55 * </p> 56 */ 57 private String[] classPath = new String[] {}; 58 59 /** 60 * <p> 61 * Internal variable used to store the name (including package information) 62 * of the Jar file's main function extracted from the Jar file's MANIFEST. 63 * </p> 64 */ 65 private String mainClassName = ""; 66 67 /** 68 * <p> 69 * Inner class that defines an exception that is thrown if launching the 70 * application in the Jar file fails. 71 * </p> 72 * 73 * @author Steffen Herbold 74 * @version 1.0 75 */ 76 private class JarLaunchException extends Exception { 77 78 /** 79 * <p> 80 * Id for object serialization. 81 * </p> 82 */ 26 83 private static final long serialVersionUID = 1L; 27 84 28 public JarLaunchException() { 29 super(); 30 } 31 85 /** 86 * <p> 87 * Constructor. Creates a new JarLaunchException. 88 * </p> 89 * 90 * @param string 91 * error message of the exception 92 */ 32 93 public JarLaunchException(String string) { 33 94 super(string); 34 95 } 35 96 97 /** 98 * <p> 99 * Constructor. Creates a new JarLaunchException as a copy of an 100 * existing exception. 101 * </p> 102 * 103 * @param e 104 * exception that is copied 105 */ 36 106 public JarLaunchException(Exception e) { 37 107 super(e); … … 40 110 } 41 111 112 /** 113 * <p> 114 * Constructor. Creates a new JarLauncher. 115 * </p> 116 * 117 * @param jarfileJjar 118 * file to be launched; must not be complete path but in relation 119 * to the current working directory 120 * @param args 121 * arguments with which the main function of the Jar file is 122 * called 123 */ 42 124 public JarLauncher(String jarfile, String[] args) { 43 125 this.jarfile = jarfile; … … 45 127 } 46 128 129 /** 130 * <p> 131 * Executes the main function of the Jar file associated with this launcher. 132 * </p> 133 */ 47 134 public void exec() { 48 135 try { 49 136 getInfoFromJar(); 50 137 initClassLoader(); 51 startSUT();138 runMain(); 52 139 } catch (JarLaunchException e) { 53 140 System.err.println("Failure to launch application."); … … 56 143 } 57 144 145 /** 146 * <p> 147 * Retrieves the classpath and main function from the Jar file's MANIFEST. 148 * </p> 149 * 150 * @throws JarLaunchException 151 * thrown if reading of Jar file or MANIFEST fails 152 */ 58 153 private void getInfoFromJar() throws JarLaunchException { 59 154 JarInputStream jarInputStream; … … 77 172 } 78 173 174 /** 175 * <p> 176 * Modifies the {@link ClassLoader} of the current VM such that it includes 177 * the class path defined in the Jar file's MANIFEST. 178 * </p> 179 * 180 * @throws JarLaunchException 181 * thrown if modification of {@link ClassLoader} fails. 182 */ 79 183 private void initClassLoader() throws JarLaunchException { 80 184 URLClassLoader classLoader = (URLClassLoader) ClassLoader … … 112 216 } 113 217 114 private void startSUT() throws JarLaunchException { 218 /** 219 * <p> 220 * Executes the main function. 221 * </p> 222 * 223 * @throws JarLaunchException 224 * thrown if execution of main function fails or the main 225 * function itself throws an exception 226 */ 227 private void runMain() throws JarLaunchException { 115 228 Class<?> mainClass; 116 229 try {
Note: See TracChangeset
for help on using the changeset viewer.