Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 package org.jboss.embedded.tomcat;
 
 import java.io.File;
 
 import  org.apache.catalina.Lifecycle;
 import  org.apache.catalina.LifecycleEvent;
 import  org.apache.catalina.LifecycleListener;
 import  org.apache.catalina.core.StandardContext;
Searches for WAR's WEB-INF directory and deploys that directory. A JBoss DeploymentContext is created and the StandardContext is added as an attachment This listener assumes an exploded deployment, in other words, that WEB-INF/ is a directory in a file system.

Author(s):
Bill Burke
adrian@jboss.org
Version:
$Revision: 1.1 $
 
 public class WebinfScanner implements LifecycleListener
 {
    private DeploymentGroup group;
 
    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");
 
           = Bootstrap.getInstance().createDeploymentGroup();
          try
          {
             if (webInfLib.exists())
             {
                .add(webInfLib.toURL());
             }
             if (webInfClasses.exists())
             {
                .add(webInfClasses.toURL());
             }
             for (DeploymentUnit deployment : .getDeploymentUnits())
             {
                deployment.getTransientManagedObjects().addAttachment(StandardContext.classcontainer);
             }
             .process();
          }
          catch (Exception e)
          {
             throw new RuntimeException(e);
          }
       }
       else if (event.getType().equals(Lifecycle.STOP_EVENT))
       {
          try
         {
            .undeploy();
         }
         catch (DeploymentException e)
         {
            throw new RuntimeException(e);
         }
      }
   }
   private static Method basePathMethod;
   private static synchronized Method getBasePathMethod()
   {
      if ( != nullreturn ;
      try
      {
          = StandardContext.class.getDeclaredMethod("getBasePath");
      }
      catch (NoSuchMethodException e)
      {
         throw new RuntimeException(e);
      }
      .setAccessible(true);
      return ;
   }
New to GrepCode? Check out our FAQ X