return path;
}
public void installModule(JarFile earFile, EARContext earContext, Module module, Collection configurationStores, ConfigurationStore targetConfigurationStore, Collection repositories) throws DeploymentException {
EARContext moduleContext;
if (module.isStandAlone()) {
moduleContext = earContext;
} else {
Environment environment = module.getEnvironment();
Artifact earConfigId = earContext.getConfigID();
Artifact configId = new Artifact(earConfigId.getGroupId(), earConfigId.getArtifactId() + "_" + module.getTargetPath(), earConfigId.getVersion(), "car");
environment.setConfigId(configId);
environment.addDependency(earConfigId, ImportType.ALL);
File configurationDir = new File(earContext.getBaseDir(), module.getTargetPath());
configurationDir.mkdirs();
// construct the web app deployment context... this is the same class used by the ear context
try {
File inPlaceConfigurationDir = null;
if (null != earContext.getInPlaceConfigurationDir()) {
inPlaceConfigurationDir = new File(earContext.getInPlaceConfigurationDir(), module.getTargetPath());
}
moduleContext = new EARContext(configurationDir,
inPlaceConfigurationDir,
environment,
ConfigurationModuleType.WAR,
module.getModuleName(),
earContext);
} catch (DeploymentException e) {
cleanupConfigurationDir(configurationDir);
throw e;
}
}
module.setEarContext(moduleContext);
module.setRootEarContext(earContext);
try {
ClassPathList manifestcp = new ClassPathList();
// add the warfile's content to the configuration
JarFile warFile = module.getModuleFile();
Enumeration<JarEntry> entries = warFile.entries();
List<ZipEntry> libs = new ArrayList<ZipEntry>();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
URI targetPath = new URI(null, entry.getName(), null);
if (entry.getName().equals("WEB-INF/web.xml")) {
moduleContext.addFile(targetPath, module.getOriginalSpecDD());
} else if (entry.getName().startsWith("WEB-INF/lib") && entry.getName().endsWith(".jar")) {
// keep a collection of all libs in the war
// libs must be installed after WEB-INF/classes which must be installed after this copy phase
libs.add(entry);
} else {
moduleContext.addFile(targetPath, warFile, entry);
}
}
// always add WEB-INF/classes to the classpath regardless of whether
// any classes exist. This must be searched BEFORE the WEB-INF/lib jar files,
// per the servlet specifications.
moduleContext.getConfiguration().addToClassPath("WEB-INF/classes/");
manifestcp.add("WEB-INF/classes/");
// install the libs
for (ZipEntry entry : libs) {
URI targetPath = new URI(null, entry.getName(), null);
moduleContext.addInclude(targetPath, warFile, entry);
manifestcp.add(entry.getName());
}
// add the manifest classpath entries declared in the war to the class loader
// we have to explicitly add these since we are unpacking the web module
// and the url class loader will not pick up a manifest from an unpacked dir
moduleContext.addManifestClassPath(warFile, RELATIVE_MODULE_BASE_URI);
moduleContext.getGeneralData().put(ClassPathList.class, manifestcp);
} catch (IOException e) {
throw new DeploymentException("Problem deploying war", e);
} catch (URISyntaxException e) {
throw new DeploymentException("Could not construct URI for location of war entry", e);
} finally {
if (!module.isStandAlone()) {
try {
moduleContext.flush();
} catch (IOException e) {
throw new DeploymentException("Problem closing war context", e);
}
}
}