org.backsource.utils.lang
Class Main

java.lang.Object
  extended byorg.backsource.utils.lang.Main

public class Main
extends java.lang.Object

A dynamic main to use instead of the normal main i jar-files to be able to load classes from jar-files inside the jarfile run by java -jar.

main makes it possible to package applications in a jar-file and run the with the java -jar XXX.jar command. This class works like a standin for the main you want to run. by specifying this class as the Main-class in the manifest it is possible to distribute lib:s the applications depends on as embedded jarfiles.

Main will add all jar-files mentioned in the Class-path attribute to the classpath without them having to exist outside the running jar-application. It will the start the main application specifyed in the Dynamic-main attribute. A normal manifest could look like this:

Main-class: org.backsource.utils.lang.Main
Class-path: lib/xerces2.0.2.jar lib/xalan2.4.D1.jar lib/xml-apis.jar lib/timutils.jar

Name: se/tim/utils/lang/Main.class
Dynamic-Main: org.backsource.utils.javadoc.XMLEscaper

The libraries would be embedded in the distributed jar-file, which could look like this:

[pra@pra jars]$ unzip -l xmlescaper.jar
Archive:  xmlescaper.jar
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  09-09-02 11:58   META-INF/
      264  09-09-02 11:58   META-INF/MANIFEST.MF
        0  08-19-02 13:28   se/
        0  05-21-02 12:41   se/tim/
        0  08-22-02 12:58   se/tim/utils/
        0  08-23-02 16:53   se/tim/utils/lang/
     4544  09-09-02 11:57   se/tim/utils/lang/Main.class
      987  09-09-02 11:57   se/tim/utils/lang/Main$MainClassLoader.class
     3174  09-09-02 11:57   se/tim/utils/lang/Main$Handler.class
        0  09-09-02 11:58   lib/
   108484  08-22-02 13:16   lib/xml-apis.jar
   933730  08-22-02 12:59   lib/xerces2.0.2.jar
   983377  08-22-02 12:59   lib/xalan2.4.D1.jar
    58971  09-03-02 10:00   lib/timutils.jar
 --------                   -------
  2093531                   14 files
} // end of main () } // end of main ()

Version:
$Revision: 1.1.1.1 $
Author:
Peter Antman

Nested Class Summary
 class Main.Handler
           
 class Main.MainClassLoader
           
 
Field Summary
static boolean debug
           
static java.util.jar.Attributes.Name DYNAMIC_MAIN
           
 
Constructor Summary
Main()
           
 
Method Summary
 void invokeClass(java.lang.String[] args)
           
static void main(java.lang.String[] args)
           
 void pwd()
           
 void setClasspath(java.lang.String jarfile, java.lang.String manifestcl)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DYNAMIC_MAIN

public static final java.util.jar.Attributes.Name DYNAMIC_MAIN

debug

public static final boolean debug
See Also:
Constant Field Values
Constructor Detail

Main

public Main()
     throws java.lang.Exception
Method Detail

setClasspath

public void setClasspath(java.lang.String jarfile,
                         java.lang.String manifestcl)
                  throws java.net.MalformedURLException,
                         java.io.IOException
Throws:
java.net.MalformedURLException
java.io.IOException

invokeClass

public void invokeClass(java.lang.String[] args)
                 throws java.lang.ClassNotFoundException,
                        java.lang.NoSuchMethodException,
                        java.lang.reflect.InvocationTargetException,
                        java.io.IOException
Throws:
java.lang.ClassNotFoundException
java.lang.NoSuchMethodException
java.lang.reflect.InvocationTargetException
java.io.IOException

pwd

public void pwd()
         throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2000-2004 Backsource. All Rights Reserved.