// Register Object MBean
try {
CommonsModelerHelper.registerModelerMBean(standardContext, objectName);
} catch (CommonsModelerException e) {
throw new DeployerException("Cannot register the object '" + standardContext + "' with the objectname '"
+ objectName + "'.", e);
}
// set the context-root
standardContext.setPath(war.getContextRoot());
// Get the URL for this War
URL warURL = null;
try {
warURL = war.getArchive().getURL();
} catch (ArchiveException e) {
throw new DeployerException("Cannot get the URL for the archive '" + war.getArchive() + "'.", e);
}
// Analyze the war archive
IWarDeployableMetadata warDeployableMetadata = null;
try {
warDeployableMetadata = new WarDeployableMetadataFactory().createDeployableMetadata(war);
} catch (DeployableMetadataException e) {
logger.error("Unable to analyze the metadata of the war '" + warURL + "'.", e);
}
// Now, get the bindings for this web application
ENCBindingHolder encBindingHolder = null;
if (warDeployableMetadata != null) {
try {
encBindingHolder = ENCBindingBuilder.analyze(warDeployableMetadata);
} catch (ENCBindingException e) {
logger.error("Unable to analyze metadata of '" + warURL + "'", e);
}
}
// File of this war
File warFile = URLUtils.urlToFile(warURL);
// docbase
String docBase = warFile.getPath();
// File and not a directory --> unpack it
if (warFile.isFile()) {
// Need to unpack the file
File unpackDir = unpack(warFile, war, earURL);
docBase = unpackDir.getPath();
}
// set the path to the war file (needs to be unpacked else it will
// be unpacked by tomcat in the webapps folder and it will try to
// deploy twice the webapp with wrong classloader)
standardContext.setDocBase(docBase);
// default XML files
standardContext.setDefaultWebXml("conf/web.xml");
standardContext.setDefaultContextXml("context.xml");
File contextXmlFile = new File(docBase + File.separator + "META-INF" + File.separator + "context.xml");
// META-INF/context.xml file support
if (contextXmlFile.exists()) {
standardContext.setConfigFile(contextXmlFile.getAbsolutePath());
}
// Set the parent class loader
standardContext.setParentClassLoader(parentClassLoader);
// Set the java delegation model
standardContext.setDelegate(true);
// Set our naming context listener
EasyBeansNamingContextListener namingContextListener = new EasyBeansNamingContextListener();
namingContextListener.setEncBindingHolder(encBindingHolder);
namingContextListener.setInjectionHolder(ejbInjectionHolder);
namingContextListener.setName(getNamingContextName(standardContext));
standardContext.addLifecycleListener(namingContextListener);
standardContext.setNamingContextListener(namingContextListener);
// Start the context
try {
standardContext.start();
} catch (LifecycleException e) {
throw new DeployerException("Cannot start the context of the War '" + warURL + "'.", e);
}
// War has been deployed
logger.info("The war ''{0}'' has been deployed on the ''{1}'' context.", war, war.getContextRoot());
}