You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Darryl Stoflet <ds...@calweb.com> on 2000/03/12 04:35:03 UTC

loading jars from web-inf/lib and determining tomcat-home dir

Hi-
	I'm running the latest version of Tomcat (got an update just 
this afternoon and built from source). I am noticing that jar files
located under an apps WEB-INF/lib directory are not loading. It seems
that there are a few issues. 
1) startup.bat is located in the $TOMCAT_HOME/bin directory. However
some code treats this as the install dir, thus I get logs under bin etc.
2)startup.bat sets the $TOMCAT_HOME variable to '..' if not set which
is good since that is set to -Dtomcat.home thus ContextManager.home
is set properly. However, logging uses relative paths to the startup 
directory instead of cm.getHome(). 
3)DefaultCMSetter only uses context.getDocBase() + "WEB-INF/lib" which
fails the checks within getJars() -  isAbsolute() && exists() && isDirectory()
Thus my jars are not loaded.

It seems there needs to be application wide enforcement of a standard way
to determine tomcat root as well as fallbacks. I see multiple locations within
the code where files paths are being built or using relative paths. Wouldn't 
this be better handled by using ContextManager.getHome and let that build the
root path and do any fallbacks in case it can't determine that correctly,

Below I included the fix for the jar loading under WEB-INF/lib that works
for me. 


	File f =  new File(base + "/WEB-INF/lib");
        if (!f.isAbsolute()) {
            ContextManager cm = context.getContextManager();
	    f = new File(cm.getHome(), base + "/WEB-INF/lib");
        }
	Vector jars = new Vector();
	getJars(jars, f);
            
	for(int i=0; i < jars.size(); ++i) {
	    String jarfile = (String) jars.elementAt(i);
	    loader.addRepository( new File(f,jarfile ));
	}



diff output:
Index: jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
retrieving revision 1.22
diff -r1.22 DefaultCMSetter.java
170a170,174
>         if (!f.isAbsolute()) {
>             // evaluate repository path relative to the context's home directory
>             ContextManager cm = context.getContextManager();
> 	    	f = new File(cm.getHome(), base + "/WEB-INF/lib");
>         }
176c180,181
< 	    loader.addRepository( new File( base + "/WEB-INF/lib/" +jarfile ));
---
> 		System.out.println("Found jar:" + jarfile);
> 	    loader.addRepository( new File(f,jarfile ));

-- 
Darryl Stoflet