|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xml.sax.helpers.DefaultHandler com.gridsystems.launcher.Launcher
public class Launcher
Allows the execution of a java application within a custom classloader.
This class allows two usage styles. It can be used as the main application class, and it will use an "XML descriptor" to construct the classloader and execute the class, or it can be used directly from code.
<!DOCTYPE launcher SYSTEM "http://www.gridsystems.com/dtds/launcher.dtd">
<launcher>
<application class="full.class.path" [method="XXX(default main)"]/>
<!-- Sets a system property with the given value -->
<property name="name" value="value"/>
<!-- Sets a system property with the given relative path -->
<property name="name" path="path"/>
</application>
<classpath>
<!-- Includes a single jar file -->
<include file="path"/>
<!-- Includes a class directory -->
<include dir="path"/>
<!-- Includes all jars in the specified path -->
<include jars="path" [recursive="true / false(default)"]/>
<!-- Includes WEB-INF/classes and WEB-INF/lib/*.jar -->
<include webapp="path"/>
</classpath>
</launcher>
The DTD URL is ficticious, and Launcher will use an internal DTD located at the
same directory as the class in the jar (via class.getResource()
).
All relative paths in the descriptor are considered relative to the "base directory". This base directory is determined as follows:
launcher.basedir
is set, uses
its value,
File tomcatHome = new File("[path to tomcat]");
Launcher launcher = new Launcher();
launcher.setClassName("[class name]");
launcher.setMethodName("[method name]");
launcher.setBaseDir(tomcatHome);
launcher.addWebapp("webapps/" + contextName);
launcher.addDir("common/classes");
launcher.addJars("common/lib");
try {
launcher.launch(args);
}
catch (LaunchException e) {
...
}
Classes in the classpath are searched for in order of addition, so the order of calls to addXXX methods is important. In the example above, classes will be searched for starting by [contextName]/WEB-INF/classes, and ending by the jars in [tomcatHome]/common/lib.
Constructor Summary | |
---|---|
Launcher()
Empty constructor. |
Method Summary | |
---|---|
void |
addDir(java.lang.String path)
Adds a single directory to the classpath. |
void |
addFile(java.lang.String path)
Adds a single file to the classpath. |
void |
addJars(java.lang.String path,
boolean recursive)
Adds all jars in the specified directory to the classpath. |
void |
addUrl(java.lang.String surl)
Adds a single URL to the classpath. |
void |
addUrl(java.net.URL url)
Adds a single URL to the classpath. |
void |
addWar(java.lang.String path)
Adds a war packed web application to the classpath. |
void |
addWebApp(java.lang.String path)
Adds a web application to the classpath. |
void |
doInherit()
Makes the generated classloader to be a child of the current context classloader. |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String qName)
|
void |
error(org.xml.sax.SAXParseException e)
|
void |
fatalError(org.xml.sax.SAXParseException e)
|
java.io.File |
getBaseDir()
Gets the base directory for all relative paths. |
void |
launch(java.lang.String[] args)
Executes the configured class and method, passing it the specified arguments, into the built class loader. |
void |
loadProperties(java.lang.String path)
Loads all properties from the specified file path and adds them as system properties. |
static void |
main(java.lang.String[] args)
Starts the launcher in "stand-alone" mode. |
org.xml.sax.InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
|
void |
setBaseDir(java.io.File dir)
Sets the base directory. |
void |
setClassName(java.lang.String className)
Sets the name of the class to execute. |
void |
setMethodName(java.lang.String methodName)
Sets the name of the method to execute. |
void |
startElement(java.lang.String ns,
java.lang.String localName,
java.lang.String qName,
org.xml.sax.Attributes atts)
|
void |
warning(org.xml.sax.SAXParseException err)
|
Methods inherited from class org.xml.sax.helpers.DefaultHandler |
---|
characters, endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Launcher()
Method Detail |
---|
public void launch(java.lang.String[] args) throws LaunchException
static public void [methodName](String[])
args
- The arguments to pass to the method
LaunchException
- If an unhandled error is thrown during the executionpublic void setClassName(java.lang.String className)
className
- The fully qualified class namepublic void setMethodName(java.lang.String methodName)
static public void [methodName](String args[]) throws Exception
methodName
- The name of the method to invokepublic java.io.File getBaseDir()
If not explicitly set, a default base directory will be selected according to the rules explained above.
public void setBaseDir(java.io.File dir)
dir
- The new base directorypublic void doInherit()
Needed to gain access to base classes in an embedded environment.
public void addDir(java.lang.String path)
path
- A path to a directory containing .class filespublic void addFile(java.lang.String path)
path
- A relativepublic void addJars(java.lang.String path, boolean recursive)
The order of the jars in path is platform dependent, so applications should not rely on them being sorted by any specific criteria.
path
- A path to a directory containing jar filesrecursive
- Whether the search will recurse into subdirectories or notpublic void addUrl(java.lang.String surl) throws org.xml.sax.SAXException
surl
- The string with the URL to add
org.xml.sax.SAXException
- In case of a syntax error in the URLpublic void addUrl(java.net.URL url)
url
- The URL to addpublic void addWebApp(java.lang.String path)
It is equivalent to:
launcher.addDir(path + "/WEB-INF/classes");
launcher.addJars(path + "/WEB-INF/lib", false);
path
- The path to the web application contextpublic void addWar(java.lang.String path)
path
- Path to the .war filepublic void loadProperties(java.lang.String path) throws java.io.IOException
path
- The path to the .properties file
java.io.IOException
- In case of read errorpublic static void main(java.lang.String[] args)
args
- The the command line argumentspublic org.xml.sax.InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
resolveEntity
in interface org.xml.sax.EntityResolver
resolveEntity
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
endElement
in interface org.xml.sax.ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void startElement(java.lang.String ns, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
startElement
in interface org.xml.sax.ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException
error
in interface org.xml.sax.ErrorHandler
error
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void fatalError(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException
fatalError
in interface org.xml.sax.ErrorHandler
fatalError
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
public void warning(org.xml.sax.SAXParseException err) throws org.xml.sax.SAXException
warning
in interface org.xml.sax.ErrorHandler
warning
in class org.xml.sax.helpers.DefaultHandler
org.xml.sax.SAXException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |