public void lifecycleEvent(LifecycleEvent event) {
if (event.getType().equals(Lifecycle.START_EVENT))
{
if (!(event.getSource() instanceof StandardContext))
return;
StandardContext container = (StandardContext)event.getSource();
container.getLoader().getClassLoader();
Method getBasePath = getBasePathMethod();
String basePath;
try
{
basePath = (String)getBasePath.invoke(container);
}
catch (Exception e)
{
throw new RuntimeException(e);
}
File webInf = new File(basePath, "WEB-INF");
File webInfLib = new File(webInf, "lib");
File webInfClasses = new File(webInf, "classes");
group = Bootstrap.getInstance().createDeploymentGroup();
try
{
if (webInfLib.exists())
{
group.add(webInfLib.toURL());
}
if (webInfClasses.exists())
{
group.add(webInfClasses.toURL());
}
for (DeploymentUnit deployment : group.getDeploymentUnits())
{
deployment.getTransientManagedObjects().addAttachment(StandardContext.class, container);
}
group.process();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
else if (event.getType().equals(Lifecycle.STOP_EVENT))
{
try
{
group.undeploy();
}
catch (DeploymentException e)
{
throw new RuntimeException(e);
}
}
}
|