public void boot(String[] args) throws Exception {
// First process the command line to pickup custom props/settings
processCommandLine(args);
// Auto set HOME_DIR to ../bin/run.jar if not set
String homeDir = props.getProperty(ServerConfig.HOME_DIR);
if (homeDir == null)
{
String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getFile();
/* The 1.4 JDK munges the code source file with URL encoding so run
* this path through the decoder so that is JBoss starts in a path with
* spaces we don't come crashing down.
*/
path = URLDecoder.decode(path, "UTF-8");
File runJar = new File(path);
File homeFile = runJar.getParentFile().getParentFile();
homeDir = homeFile.getCanonicalPath();
}
props.setProperty(ServerConfig.HOME_DIR, homeDir);
// Setup HOME_URL too, ServerLoader needs this
String homeURL = props.getProperty(ServerConfig.HOME_URL);
if (homeURL == null)
{
File file = new File(homeDir);
homeURL = file.toURL().toString();
props.setProperty(ServerConfig.HOME_URL, homeURL);
}
// Load the server instance
ServerLoader loader = new ServerLoader(props);
/* If there is a patch dir specified make it the first element of the
loader bootstrap classpath. If its a file url pointing to a dir, then
add the dir and its contents.
*/
if (bootURL != null)
{
if (bootURL.getProtocol().equals("file"))
{
File dir = new File(bootURL.getFile());
if (dir.exists())
{
// Add the local file patch directory
loader.addURL(dir.toURL());
// Add the contents of the directory too
File[] jars = dir.listFiles(new JarFilter());
for (int j = 0; jars != null && j < jars.length; j++)
{
loader.addURL(jars[j].getCanonicalFile().toURL());
}
}
}
else
{
loader.addURL(bootURL);
}
}
// Add any extra libraries
for (int i = 0; i < bootLibraries.size(); i++)
{
loader.addLibrary(bootLibraries.get(i));
}
// Add the jars from the endorsed dir
loader.addEndorsedJars();
// jmx UnifiedLoaderRepository needs a concurrent class...
loader.addLibrary(concurrentLib);
// Add any extra libraries after the boot libs
for (int i = 0; i < extraLibraries.size(); i++)
{
loader.addLibrary(extraLibraries.get(i));
}
// Add any extra classapth URLs
for (int i = 0; i < extraClasspath.size(); i++)
{
loader.addURL(extraClasspath.get(i));
}
// Load the server
ClassLoader parentCL = Thread.currentThread().getContextClassLoader();
server = loader.load(parentCL);
// Initialize the server
server.init(props);
// Start 'er up mate!
server.start();
}
|