The attached patch file contains diffs for adding the
following feature to startup.Main:

 - supports two new configuration properties:

  org.apache.tomcat.common.classpath  and
  org.apache.tomcat.shared.classpath

 - builds URLs to each jar and directory in the
   above two class paths and prepends them to
   the URL arrays used to initialize the 'common'
   and 'shared' classloaders.  This allows one
   to configure the common and shared ClassLoaders
   without having to physically place files into
   TOMCAT_HOME/lib/common/ and ../lib/shared
   directories.

 - added some needed javadoc comments (not nearly
   enough).

 - fixed a couple tiny bugs (nothing serious).

Hopefully a committer (Ignacio?) will have no trouble
with this patch file.  Lemme know if you need any
help.

Cheers,

Mel


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/
Index: Main.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/startup/Main.java,v
retrieving revision 1.25
diff -u -r1.25 Main.java
--- Main.java   2001/02/10 19:17:28     1.25
+++ Main.java   2001/02/25 21:53:07
@@ -1,4 +1,10 @@
 /*
+ * $Source$
+ * $Revision$
+ * $Date$
+ * $Author$
+ */
+/*
  * ====================================================================
  *
  * The Apache Software License, Version 1.1
@@ -69,22 +75,101 @@
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.tomcat.util.compat.Jdk11Compat;
 
-// Depends:
-// JDK1.1
-// tomcat.util.IntrospectionUtils, util.compat
 
 /**
- * Starter for Tomcat.
- *
- * This is a replacement/enhancement for the .sh and .bat files - you can
- * use JDK1.2 "java -jar tomcat.jar", or ( for jdk 1.1 ) you just need to
- * include a single jar file in the classpath.
- *
- * @author Costin Manolache
- * @author Ignacio J. Ortega
- *
+       Starter class for Tomcat.
+       <p>
+       This is a replacement/enhancement for the .sh and .bat files - you can
+       use JDK1.2 "java -jar tomcat.jar", or ( for jdk 1.1 ) you just need to
+       include a single jar file in the classpath.
+       <p>
+       This class creates three class loader instances: 
+       <ol>
+       <li>a 'common' loader to be the parent of both the server
+           container and also webapp loaders.</li>
+       <li>a 'shared' loader to load classes used by all webapps, but
+           not the servlet engine.</i>
+       <li>a 'server' loader exclusively for the tomcat servlet engine.</li>
+       </ol>
+       Both the 'shared' loader and 'server' loader have the common loader as
+       the parent class loader.  The class path for each is assembled like so:
+       <ul>
+       <li>common - all elements of the 
+<code>org.apache.tomcat.common.classpath</code>
+             property plus all *.jar files found in ${TOMCAT_HOME}/lib/common/.</li>
+       <li>shared - all elements of the 
+<code>org.apache.tomcat.shared.classpath</code>
+             property plus all *.jar files found in ${TOMCAT_HOME}/lib/shared/.</i>
+       <li>server - all jar files found in ${TOMCAT_HOME}/lib, plus the class
+             folder ${TOMCAT_HOME}/classes and finally also the utility jar
+             file ${JAVA_HOME}/lib/tools.jar.</li>
+       </ol>
+       After creating the above class loaders, this class instantiates, initializes
+       and starts an instance of the class 
+<code>org.apache.tomcat.startup.Tomcat</code>.
+       <p>
+       @author Costin Manolache
+       @author Ignacio J. Ortega
+       @author Mel Martinez [EMAIL PROTECTED]
+       @version $Revision$ $Date$
  */
 public class Main {
+
+       /**
+               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.tomcat.shared.classpath = /home/mypath/lib/mylib.jar: \
+               *                                      /home/mypath/classes/
+               </code></pre>
+       */
+       public static final String TOMCAT_SHARED_CLASSPATH_PROPERTY =
+               "org.apache.tomcat.shared.classpath";
+
+       /**
+               the classpath shared among all web apps (in addition to any
+               jar files placed directly in $TOMCAT_HOME/lib/shared/).
+       */
+       public static final String TOMCAT_SHARED_CLASSPATH;
+       
+       /**
+               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.tomcat.common.classpath = /home/mypath/lib/mylib.jar: \
+               *                                      /home/mypath/classes/
+               </code></pre>
+       */
+       public static final String TOMCAT_COMMON_CLASSPATH_PROPERTY =
+               "org.apache.tomcat.common.classpath";
+
+       /**
+               the classpath common to both the servlet engine and also to
+               any web applications served by it (in addition to any
+               jar files placed directly in $TOMCAT_HOME/lib/common/).
+       */
+       public static final String TOMCAT_COMMON_CLASSPATH;
+       
+       static{
+               String s=null;
+               s = System.getProperty(TOMCAT_SHARED_CLASSPATH_PROPERTY);
+               if(s==null){
+                       s="";
+               }
+               TOMCAT_SHARED_CLASSPATH=s;
+               s=null;
+               s = System.getProperty(TOMCAT_COMMON_CLASSPATH_PROPERTY);
+               if(s==null){
+                       s="";
+               }
+               TOMCAT_COMMON_CLASSPATH=s;
+       }
+
     String installDir;
     String libBase;
     String serverBase;
@@ -110,108 +195,178 @@
     }
 
     void log( String s ) {
-       System.out.println("TomcatStartup: " + s );
+       System.err.println("TomcatStartup: " + s );
     }
 
     // -------------------- Utils --------------------
     
-    public String checkDir( String base ) {
-        String r=null;
-        try {
-           File f = new File(base);
-           r = f.getCanonicalPath();
-           if( ! r.endsWith("/") ) r+="/";
-        } catch (IOException ioe) {
-           ioe.printStackTrace();
-            r=base;
-        }
-        return r;
-    }
+       public static String checkDir( String base ) {
+               String r=null;
+               try {
+                       File f = new File(base);
+                       r = f.getCanonicalPath();
+                       if( ! r.endsWith("/") ) r+="/";
+               } catch (IOException ioe) {
+                       ioe.printStackTrace();
+                       r=base;
+               }
+               return r;
+       }
 
-    URL getURL( String base, String file ) {
-        try {
-           if( ! base.endsWith( "/" ) )
-               base=base + "/";
-
-           File f = new File(base + file);
-           String path = f.getCanonicalPath();
-           if( f.isDirectory() )
-               path +="/";
-           return new URL( "file", null, path );
-        } catch (Exception ex) {
-           ex.printStackTrace();
-           return null;
-        }
+    public static URL getURL( String base, String file ) {
+               try {
+                       File baseF = new File(base);
+                       File f = new File(baseF,file);
+                       String path = f.getCanonicalPath();
+                       if( f.isDirectory() ){
+                               path +="/";
+                       }
+                       return new URL( "file", null, path );
+               } catch (Exception ex) {
+                       ex.printStackTrace();
+                       return null;
+               }
     }
 
     public String getServerDir() {
-       if( libBase!=null ) return libBase;
-
-       if( homeDir!=null ) libBase=checkDir( homeDir + "/lib");
-       else libBase=checkDir("./lib");
-       return libBase;
+               if( libBase!=null ){
+                       return libBase;
+               }
+               if( homeDir!=null ){
+                       libBase=checkDir( homeDir + "/lib");
+               }else{
+                       libBase=checkDir("./lib");
+               }
+               return libBase;
     }
+    
     public String getSharedDir() {
-       if( serverBase!=null ) return serverBase;
-
-       if( homeDir!=null ) serverBase=checkDir( homeDir + "/lib/shared");
-       else serverBase=checkDir("./lib/shared");
-       return serverBase;
+               if( serverBase!=null ){
+                       return serverBase;
+               }
+               if( homeDir!=null ){
+                       serverBase=checkDir( homeDir + "/lib/shared");
+               }else{
+                       serverBase=checkDir("./lib/shared");
+               }
+               return serverBase;
     }
+    
     public String getCommonDir() {
-       if( commonBase!=null ) return commonBase;
-
-       if( homeDir!=null ) commonBase=checkDir( homeDir + "/lib/common");
-       else commonBase=checkDir("./lib/common");
-       return commonBase;
+               if( commonBase!=null ){
+                       return commonBase;
+               }
+               if( homeDir!=null ){
+                       commonBase=checkDir( homeDir + "/lib/common");
+               }else{
+                       commonBase=checkDir("./lib/common");
+               }
+               return commonBase;
     }
 
+       /**
+               add elements from the classpath <i>cp</i> to a Vector
+               <i>jars</i> as file URLs (We use Vector for JDK 1.1 compat).
+               <p>
+               @param <b>cp</b> a String classpath of directory or jar file
+                               elements separated by path.separator delimiters.
+               @return a Vector of URLs. 
+       */
+       public static Vector getJarsFromClassPath(String cp)
+       throws IOException,MalformedURLException{
+               Vector jars = new Vector();
+               String sep = System.getProperty("path.separator");
+               String token;
+               StringTokenizer st;
+               if(cp!=null){
+                       st = new StringTokenizer(cp,sep);
+                       while(st.hasMoreTokens()){
+                               File f = new File(st.nextToken());
+                               String path = f.getCanonicalPath();
+                               if(f.isDirectory()){
+                                       path += "/";
+                               }
+                               URL url = new URL("file",null,path);
+                               if(!jars.contains(url)){
+                                       jars.addElement(url);
+                               }
+                       }
+               }
+               return jars;
+       }
+
     static final Jdk11Compat jdk11Compat=Jdk11Compat.getJdkCompat();
     
-    void execute( String args[] ) throws Exception {
+    protected void execute( String args[] ) throws Exception {
 
-        try {
-            homeDir=IntrospectionUtils.guessHome("tomcat.home", "tomcat.jar");
-           // System.out.println("Guessed home=" + homeDir);
-
-           ClassLoader parentL=this.getClass().getClassLoader();
-           //System.out.println("ParentL " + parentL );
-            // the server classloader loads from classes dir too and from tools.jar
-            Vector urlV=new Vector();
-            urlV.addElement( getURL(  getServerDir() ,"../classes/" ));
-            Vector serverUrlV =getClassPathV(getServerDir());
-            for(int i=0; i < serverUrlV.size();i++)
-                urlV.addElement(serverUrlV.elementAt(i));
-           urlV.addElement( new URL( "file", null ,
-                                     System.getProperty( "java.home" ) +
-                                     "/../lib/tools.jar"));
-            URL[] serverClassPath=getURLs(urlV);
-            // ClassLoader for webapps it uses a shared dir as repository,
-           // distinct from lib
-
-            URL[] sharedClassPath=getURLs(getClassPathV(getSharedDir()));
-            URL[] commonClassPath=getURLs(getClassPathV(getCommonDir()));
-
-           ClassLoader commonCl=
-               jdk11Compat.newClassLoaderInstance(commonClassPath , parentL );
-           ClassLoader sharedCl=
-               jdk11Compat.newClassLoaderInstance(sharedClassPath ,commonCl );
-            ClassLoader serverCl=
-               jdk11Compat.newClassLoaderInstance(serverClassPath ,commonCl);
-
-           Class cls=serverCl.loadClass("org.apache.tomcat.startup.Tomcat");
-           Object proxy=cls.newInstance();
-
-            IntrospectionUtils.setAttribute( proxy,"args", args );
-           IntrospectionUtils.setAttribute( proxy,"home", homeDir );
-            IntrospectionUtils.setAttribute( proxy,"parentClassLoader",
-                                            sharedCl );
-            IntrospectionUtils.execute(  proxy, "execute" );
-           return;
-       } catch( Exception ex ) {
-           System.out.println("Guessed home=" + homeDir);
-           ex.printStackTrace();
-       }
+               try {
+                       homeDir=IntrospectionUtils.guessHome("tomcat.home", 
+"tomcat.jar");
+                       // System.out.println("Guessed home=" + homeDir);
+
+                       ClassLoader parentL=this.getClass().getClassLoader();
+                       //System.out.println("ParentL " + parentL );
+                       // the server classloader loads from classes dir too and from 
+tools.jar
+                       Vector serverJars=new Vector();
+                       serverJars.addElement( getURL(  getServerDir() ,"../classes/" 
+));
+                       Vector serverUrlV =getClassPathV(getServerDir());
+                       for(int i=0; i < serverUrlV.size();i++){
+                               serverJars.addElement(serverUrlV.elementAt(i));
+                       }
+                       serverJars.addElement( new URL( "file", null ,
+                                                                     
+System.getProperty( "java.home" ) +
+                                                                     
+"/../lib/tools.jar"));
+
+                       
+                       Vector commonDirJars = getClassPathV(getCommonDir());
+                       Vector commonJars = 
+getJarsFromClassPath(TOMCAT_COMMON_CLASSPATH);
+                       Enumeration jars = commonDirJars.elements();
+                       while(jars.hasMoreElements()){
+                               URL url = (URL)jars.nextElement();
+                               if(!commonJars.contains(url)){
+                                       commonJars.addElement(url);
+                               }
+                       }
+                       Vector sharedDirJars = getClassPathV(getSharedDir());
+                       Vector sharedJars = 
+getJarsFromClassPath(TOMCAT_SHARED_CLASSPATH);
+                       jars = sharedDirJars.elements();
+                       while(jars.hasMoreElements()){
+                               URL url = (URL)jars.nextElement();
+                               if(!sharedJars.contains(url)){
+                                       sharedJars.addElement(url);
+                               }
+                       }
+//log("System classpath = ");
+//getURLs(getJarsFromClassPath(System.getProperty("java.class.path")));
+//log(" System classloader = "+parentL+"\n");
+//log("setting up common classpath....");
+                       URL[] commonClassPath=getURLs(commonJars);
+                       ClassLoader commonCl=
+                               jdk11Compat.newClassLoaderInstance(commonClassPath , 
+parentL );
+//log(" common classloader = "+commonCl+"\n");
+//log("setting up shared classpath...");
+                       URL[] sharedClassPath=getURLs(sharedJars);
+                       ClassLoader sharedCl=
+                               jdk11Compat.newClassLoaderInstance(sharedClassPath 
+,commonCl );
+//log(" shared classloader = "+sharedCl+"\n");
+//log("setting up server classpath...");
+                       URL[] serverClassPath=getURLs(serverJars);
+                       ClassLoader serverCl=
+                               jdk11Compat.newClassLoaderInstance(serverClassPath 
+,commonCl);
+//log(" server classloader = "+serverCl+"\n");
+
+
+                       Class 
+cls=serverCl.loadClass("org.apache.tomcat.startup.Tomcat");
+                       Object proxy=cls.newInstance();
+
+                       IntrospectionUtils.setAttribute(proxy,"args", args );
+                       IntrospectionUtils.setAttribute(proxy,"home", homeDir );
+                       
+IntrospectionUtils.setAttribute(proxy,"parentClassLoader",sharedCl);
+                       IntrospectionUtils.execute(  proxy, "execute" );
+                       return;
+               } catch( Exception ex ) {
+                       System.out.println("Guessed home=" + homeDir);
+                       ex.printStackTrace();
+               }
     }
 
     // -------------------- Command-line args processing --------------------
@@ -305,8 +460,9 @@
 
     private URL[] getURLs(Vector v){
         URL[] urls=new URL[ v.size() ];
-       for( int i=0; i<v.size(); i++ ) {
+               for( int i=0; i<v.size(); i++ ) {
             urls[i]=(URL)v.elementAt( i );
+//log("\tloading url["+i+"] = "+urls[i]); 
         }
         return urls;
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to