Author: norman
Date: Sun May 23 15:43:49 2010
New Revision: 947434

URL: http://svn.apache.org/viewvc?rev=947434&view=rev
Log:
Add support for automatic adding jars to classpath when adding them to 
conf/lib. This is similar to what we had in james-2.3.x with SAR-INF/lib 
folder. Thx to Eric Charles for the patch. See JAMES-1003

Added:
    
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesClassLoader.java
Modified:
    james/server/trunk/spring-deployment/pom.xml
    
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
    
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
    
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java

Modified: james/server/trunk/spring-deployment/pom.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/pom.xml?rev=947434&r1=947433&r2=947434&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/pom.xml (original)
+++ james/server/trunk/spring-deployment/pom.xml Sun May 23 15:43:49 2010
@@ -52,7 +52,7 @@
           
<includeConfigurationDirectoryInClasspath>true</includeConfigurationDirectoryInClasspath>
           <environmentSetupFileName>setenv</environmentSetupFileName>
           <!--  set some sane defaults for memory -->
-          <extraJvmArguments>-Xms128m -Xmx512m</extraJvmArguments>
+          <extraJvmArguments>-Xms128m -Xmx512m 
-Djava.system.class.loader=org.apache.james.container.spring.JamesClassLoader</extraJvmArguments>
           <!-- Generate bin scripts for windows and unix per default -->
           <platforms>
             <platform>windows</platform>
@@ -132,6 +132,10 @@
                       <name>wrapper.java.maxmemory</name>
                       <value>512</value>
                     </property>
+                    <property>
+                      <name>wrapper.java.additional.1</name>
+                      
<value>-Djava.system.class.loader=org.apache.james.container.spring.JamesClassLoader</value>
+                    </property>
                   </configuration>
                 </generatorConfiguration>
               </generatorConfigurations>

Added: 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesClassLoader.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesClassLoader.java?rev=947434&view=auto
==============================================================================
--- 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesClassLoader.java
 (added)
+++ 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesClassLoader.java
 Sun May 23 15:43:49 2010
@@ -0,0 +1,65 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.container.spring;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * The JamesClassLoader uses the provided system classloader
+ * and adds all jars found in the external library directory.
+ * 
+ * Use 
"-Djava.system.class.loader=org.apache.james.container.spring.JamesClassLoader"
+ * when launching james for this class loader to be invoked.
+ */
+public class JamesClassLoader extends URLClassLoader {
+
+    /**
+     * The ClassLoader that will be used by James application.
+     * 
+     * The class is loaded using the default system class loader 
+     * defines this constructor with a single parameter is used as 
+     * the delegation parent.
+     * 
+     * @param classLoader
+     */
+    public JamesClassLoader(ClassLoader classLoader) {
+        super(new URL[0], classLoader);
+        String[] jars = new 
File(JamesServerApplicationContext.getResourceLoader().getExternalLibraryDirectory()).list(new
 FilenameFilter() {
+            public boolean accept(File dir, String name) {
+                return name.endsWith(".jar");
+            }
+        });
+        if (jars != null) {
+            for (int i=0; i < jars.length; i++) {
+                File file = new 
File(JamesServerApplicationContext.getResourceLoader().getExternalLibraryDirectory()
 + jars[i]);
+                try {
+                    super.addURL(file.toURI().toURL());
+                } catch (MalformedURLException e) {
+                       // At that time, we can not yet use non jvm classes for 
logging. Simply log on console. Should never come here...
+                       System.out.println("Got an unexpected exception while 
building the urls for the james class loader for file " + 
file.getAbsolutePath());
+                }
+            }
+        }
+    }
+
+}

Modified: 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java?rev=947434&r1=947433&r2=947434&view=diff
==============================================================================
--- 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
 (original)
+++ 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
 Sun May 23 15:43:49 2010
@@ -56,4 +56,6 @@ public interface JamesResourceLoader ext
      * @return rootDir
      */
     public String getRootDirectory();
+
+    
 }

Modified: 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java?rev=947434&r1=947433&r2=947434&view=diff
==============================================================================
--- 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
 (original)
+++ 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
 Sun May 23 15:43:49 2010
@@ -23,50 +23,15 @@ import org.springframework.context.suppo
 import org.springframework.core.io.Resource;
 
 /**
- * {...@link ApplicationContext} which loads all needed beans for JAMES
+ * {...@link ApplicationContext} which loads all needed Spring beans for JAMES
  *
  */
 public class JamesServerApplicationContext extends 
ClassPathXmlApplicationContext implements JamesResourceLoader{
-
+       
     /**
      * The resourceloader to use. This must be defined as static, otherwise it 
will fail to startup..
      */
-    private final static JamesResourceLoader resourceLoader = new 
AbstractJamesResourceLoader() {
-
-        /*
-         * (non-Javadoc)
-         * @see 
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
-         */
-        public String getAbsoluteDirectory() {
-            return "/";
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see 
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
-         */
-        public String getConfDirectory() {
-            return getRootDirectory() + "/conf/";
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see 
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
-         */
-        public String getVarDirectory() {
-            return getRootDirectory() + "/var/";
-        }
-
-        /*
-         * (non-Javadoc)
-         * @see 
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
-         */
-        public String getRootDirectory() {
-            return "../";
-        }
-
-    };
-    
+    private final static JamesServerResourceLoader resourceLoader = new 
JamesServerResourceLoader();
     
     public JamesServerApplicationContext(String[] configs) {
        super(configs);
@@ -116,5 +81,60 @@ public class JamesServerApplicationConte
     public String getRootDirectory() {
         return resourceLoader.getRootDirectory();
     }
+    
+    /**
+     * Protected accessor for the resource loader.
+     */
+    protected static JamesServerResourceLoader getResourceLoader() {
+       return resourceLoader;
+    }
+    
+    protected static final class JamesServerResourceLoader extends 
AbstractJamesResourceLoader {
+
+        /*
+         * (non-Javadoc)
+         * @see 
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
+         */
+        public String getAbsoluteDirectory() {
+            return "/";
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see 
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
+         */
+        public String getConfDirectory() {
+            return getRootDirectory() + "/conf/";
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see 
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
+         */
+        public String getVarDirectory() {
+            return getRootDirectory() + "/var/";
+        }
+
+
+        /**
+         * Return the directory where the external jar libraries must be 
placed by the
+         * administrator. The jars may contain mailets, jdbc drivers,...
+         * 
+         * @return externalLibraryDirectory
+         */
+        public String getExternalLibraryDirectory() {
+            return getRootDirectory() + "/conf/lib/";
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see 
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
+         */
+        public String getRootDirectory() {
+            return "../";
+        }
+        
+    };
+    
 
 }

Modified: 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java?rev=947434&r1=947433&r2=947434&view=diff
==============================================================================
--- 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
 (original)
+++ 
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
 Sun May 23 15:43:49 2010
@@ -81,7 +81,6 @@ public class JamesServerWebApplicationCo
                 return varDirectory;
             }
         }
-
     };
     private String rootDirectory;
     private String absoluteDirectory;
@@ -120,6 +119,7 @@ public class JamesServerWebApplicationCo
     public void setConfDirectory(String confDirectory) {
         this.confDirectory = confDirectory;
     }
+    
     /*
      * (non-Javadoc)
      * @see 
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()



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

Reply via email to