Also filed as Bug 3368 (http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3368). Tomcat 3.3 provides two system properties that can be used to add to the jar files automatically added to apps and common ClassLoaders from Tomcat directory structure. There are legitimate reasons why one might want to do this: - Many do not like adding application jars to an installed product's lib - Symbolic links are not cross platform (and ant doesn't support symbolic links and we still end up with application jars in Tomcat lib) How about providing two similar properties in Catalina? org.apache.catalina.common.classpath and org.apache.catalina.shared.classpath? (Can't we all get along?) -arun --- catalina/src/share/org/apache/catalina/startup/Bootstrap.java-1.24 Sat Sep 1 03:13:18 2001 +++ catalina/src/share/org/apache/catalina/startup/Bootstrap.java Sat Sep 1 09:25:58 2001 @@ -71,6 +71,8 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; import org.apache.catalina.loader.Extension; import org.apache.catalina.loader.StandardClassLoader; @@ -223,6 +225,21 @@ /** + name of configuration property to set (using the -D option at + startup or via .properties file) to specify the classpath + to be used by the ClassLoader common to both the servlet engine + and all web applications. Specify this string as + normal file paths separated by the path.seperator delimiter for + the host platform. Example (unix): + <pre><code> + * org.apache.catalina.common.classpath = /home/mypath/lib/mylib.jar: \ + * /home/mypath/classes/ + </code></pre> + */ + public static final String CATALINA_COMMON_CLASSPATH_PROPERTY = + "org.apache.catalina.common.classpath"; + + /** * Construct and return the class loader to be used for loading * of the shared system classes. * @@ -286,6 +303,8 @@ } } + addClassPathToList(list, System.getProperty(CATALINA_COMMON_CLASSPATH_PROPERTY)); + // Construct the class loader itself String array[] = (String[]) list.toArray(new String[list.size()]); StandardClassLoader loader = new StandardClassLoader(array); @@ -369,6 +388,21 @@ /** + name of configuration property to set (using the -D option at + startup or via .properties file) to specify the classpath + to be used by the ClassLoader shared amongst all web applications + (but not by the servlet container). Specify this string as + normal file paths separated by the path.seperator delimiter for + the host platform. Example (unix): + <pre><code> + * org.apache.catalina.shared.classpath = /home/mypath/lib/mylib.jar: \ + * /home/mypath/classes/ + </code></pre> + */ + public static final String CATALINA_SHARED_CLASSPATH_PROPERTY = + "org.apache.catalina.shared.classpath"; + + /** * Construct and return the class loader to be used for shared * extensions by web applications loaded with Catalina. * @@ -431,6 +465,8 @@ } } + addClassPathToList(list, System.getProperty(CATALINA_SHARED_CLASSPATH_PROPERTY)); + // Construct the class loader itself String array[] = (String[]) list.toArray(new String[list.size()]); StandardClassLoader loader = new StandardClassLoader(array, parent); @@ -449,6 +485,38 @@ return (loader); + } + + private static void addClassPathToList(List list, String classpath) { + if(classpath != null) { + StringTokenizer tokenizer = new StringTokenizer(classpath, System.getProperty("path.separator")); + while(tokenizer.hasMoreTokens()) { + String filename = tokenizer.nextToken(); + File file = new File(filename); + if (file.exists() && file.canRead()) { + try { + String canonicalPath = file.getCanonicalPath(); + if(file.isDirectory()) { + // StandardClassLoader uses File.separator to designate a directory + canonicalPath += File.separator; + } + URL url = new URL("file", null, canonicalPath); + if (debug >= 1) + log(" Adding " + url.toString()); + list.add(url.toString()); + } catch (IOException e) { + System.out.println("Cannot create URL for " + + filename); + e.printStackTrace(System.out); + System.exit(1); + } + } + else { + if (debug >= 1) + log(" Did not find or could not read " + filename); + } + } + } }