Changeset 265


Ignore:
Timestamp:
11/30/11 13:46:47 (12 years ago)
Author:
sherbold
Message:
  • code documentation and formatting
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JFCMonitor/src/de/ugoe/cs/eventbench/jfcmonitor/JarLauncher.java

    r264 r265  
    1212import java.util.jar.Manifest; 
    1313 
     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 */ 
    1428public class JarLauncher { 
    1529 
    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                 */ 
    2683                private static final long serialVersionUID = 1L; 
    2784 
    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                 */ 
    3293                public JarLaunchException(String string) { 
    3394                        super(string); 
    3495                } 
    3596 
     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                 */ 
    36106                public JarLaunchException(Exception e) { 
    37107                        super(e); 
     
    40110        } 
    41111 
     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         */ 
    42124        public JarLauncher(String jarfile, String[] args) { 
    43125                this.jarfile = jarfile; 
     
    45127        } 
    46128 
     129        /** 
     130         * <p> 
     131         * Executes the main function of the Jar file associated with this launcher. 
     132         * </p> 
     133         */ 
    47134        public void exec() { 
    48135                try { 
    49136                        getInfoFromJar(); 
    50137                        initClassLoader(); 
    51                         startSUT(); 
     138                        runMain(); 
    52139                } catch (JarLaunchException e) { 
    53140                        System.err.println("Failure to launch application."); 
     
    56143        } 
    57144 
     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         */ 
    58153        private void getInfoFromJar() throws JarLaunchException { 
    59154                JarInputStream jarInputStream; 
     
    77172        } 
    78173 
     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         */ 
    79183        private void initClassLoader() throws JarLaunchException { 
    80184                URLClassLoader classLoader = (URLClassLoader) ClassLoader 
     
    112216        } 
    113217 
    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 { 
    115228                Class<?> mainClass; 
    116229                try { 
Note: See TracChangeset for help on using the changeset viewer.