I would like to extend WebappLoader to use libraries that are placed out
of my webapp dir, but when I try to start the server, I obtain the following
error:
Nov 30, 2006 11:38:07 AM es.tid.psstlatam.tomcat.CustomWebappLoader start
INFO: CustomWebappLoader start:
/etc/opt/psbatlatam/ar/pmg/pod/;/opt/install/psbatlatam/apache-
tomcat-5.5.20/common/lib/servlet-api.
jar
Nov 30, 2006 11:38:07 AM es.tid.psstlatam.tomcat.CustomWebappLoader start
INFO: CustomWebappLoader start -> dir fileName:
/etc/opt/psbatlatam/ar/pmg/pod/
Nov 30, 2006 11:38:07 AM es.tid.psstlatam.tomcat.CustomWebappLoader start
INFO: CustomWebappLoader start -> dir fileName:
/opt/install/psbatlatam/apache-tomcat-5.5.20/common/lib/servlet-api.jar
Nov 30, 2006 11:38:08 AM org.apache.catalina.startup.ContextConfig start
FINE: ContextConfig: Processing START
Nov 30, 2006 11:38:08 AM
org.apache.catalina.startup.ContextConfigprocessDefaultWebConfig
FINE: Processing context [/pod] web configuration resource
file:///opt/install/psbatlatam/apache-tomcat-5.5.20/conf/web.xml
Nov 30, 2006 11:38:11 AM
org.apache.catalina.startup.ContextConfigdefaultWebConfig
FINE: Processed default web.xml /opt/install/psbatlatam/apache-
tomcat-5.5.20/conf/web.xml 2805
Nov 30, 2006 11:38:11 AM
org.apache.catalina.startup.ContextConfigapplicationWebConfig
FINE: Parsing application web.xml file at
jndi:/localhost/pod/WEB-INF/web.xml
Nov 30, 2006 11:38:11 AM org.apache.catalina.startup.ContextConfig start
FINE: Pipeline Configuration:
Nov 30, 2006 11:38:11 AM org.apache.catalina.startup.ContextConfig start
FINE: org.apache.catalina.core.StandardContextValve/1.0
Nov 30, 2006 11:38:11 AM org.apache.catalina.startup.ContextConfig start
FINE: ======================
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Caused by: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(
WebappClassLoader.java:1815)
at org.apache.catalina.loader.WebappClassLoader.findClass(
WebappClassLoader.java:869)
at org.apache.catalina.loader.WebappClassLoader.loadClass(
WebappClassLoader.java:1322)
at org.apache.catalina.loader.WebappClassLoader.loadClass(
WebappClassLoader.java:1201)
at org.apache.catalina.core.StandardWrapper.loadServlet(
StandardWrapper.java:1034)
at org.apache.catalina.core.StandardWrapper.load (
StandardWrapper.java:932)
at org.apache.catalina.core.StandardContext.loadOnStartup(
StandardContext.java:3951)
at org.apache.catalina.core.StandardContext.start(
StandardContext.java:4225)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java
:1013)
at org.apache.catalina.core.StandardHost.start(StandardHost.java
:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(
StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(
StandardService.java:450)
at org.apache.catalina.core.StandardServer.start (
StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
... 6 more
Tomcat don't find HttpServlet.class, but It seems that my
CustomWebappLoader add this jar (/opt/install/psbatlatam/apache-
tomcat-5.5.20/common/lib/servlet-api.jar) to the repository. I have
implemented a CustomWebappLoader as follow:
public class CustomWebappLoader extends WebappLoader {
private String classPath;
protected static Log log = LogFactory.getLog( CustomWebappLoader.class);
public String getClassPath() {
return classPath;
}
// Called by tomcat to set the property
public void setClassPath(String cp) {
classPath=cp;
}
public CustomWebappLoader() {
super();
log.info("CustomWebappLoader constructor");
}
/*public void init() {
super.init();
}*/
public CustomWebappLoader(ClassLoader parent) {
super(parent);
log.info("CustomWebappLoader constructor parent: " +
parent.getClass().getName());
}
public void addRepository(String repository) {
log.debug ("[CL] AddRepository called with argument:
"+repository);
}
public void start() throws LifecycleException {
log.info("CustomWebappLoader start: " + classPath);
if(classPath==null || classPath.length()==0) return;
String [] classPathItems=classPath.split(";");
for(int i=0; i<classPathItems.length; i++) {
// Check if the item specifies a set of jar files
String classPathItem=classPathItems[i];
int index=classPathItem.indexOf("/*.jar");
if(index!=-1) {
String jarDir=classPathItem.substring(0, index+1);
log.debug("[CCL] jardir: "+jarDir);
File dir=new File(jarDir);
File[] jars=dir.listFiles();
for(int j=0; j<jars.length; j++) {
String jarFileName=jars[j].getName();
if(jarFileName.endsWith(".jar")) {
log.info("CustomWebappLoader start -> jar
fileName: " + jarFileName);
super.addRepository ("file:/"+jarDir+jarFileName);
}
}
} else {
log.info("CustomWebappLoader start -> dir fileName: " +
classPathItem);
super.addRepository("file:/"+classPathItem);
}
}
super.start();
}
}
In the server.xml I have added:
<Context path="/pod"
docBase="/opt/psbatlatam/ar/Radius_disconnection_web/" debug="0"
privileged="true" reloadable="true">
<!-- classPath contains semicolon separated list of
directories containing
classes or path/*.jar for getting all the jars in the
specified path -->
<Loader className="
es.tid.psstlatam.tomcat.CustomWebappLoader" delegate="false"
classPath="/etc/opt/psbatlatam/ar/pmg/
pod/;/opt/install/psbatlatam/apache-tomcat-5.5.20/common/lib/servlet-
api.jar"/>
</Context>
Can anyone help me, please??
Thanks, Joaquin