You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ho...@apache.org on 2006/11/14 03:05:33 UTC

svn commit: r474625 - in /incubator/solr/trunk: CHANGES.txt example/solr/README.txt src/java/org/apache/solr/core/Config.java

Author: hossman
Date: Mon Nov 13 18:05:32 2006
New Revision: 474625

URL: http://svn.apache.org/viewvc?view=rev&rev=474625
Log:
SOLR-68 - new ClassLoader that knows about jars in solr/lib/ used for accessing resources specified in Config files, ie: plugins.  Added example/solr/README.txt while i was at it so the various subdirs including 'lib' would be documented.

Added:
    incubator/solr/trunk/example/solr/README.txt   (with props)
Modified:
    incubator/solr/trunk/CHANGES.txt
    incubator/solr/trunk/src/java/org/apache/solr/core/Config.java

Modified: incubator/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/CHANGES.txt?view=diff&rev=474625&r1=474624&r2=474625
==============================================================================
--- incubator/solr/trunk/CHANGES.txt (original)
+++ incubator/solr/trunk/CHANGES.txt Mon Nov 13 18:05:32 2006
@@ -63,7 +63,9 @@
     useful in AJAX with dynamic script tags for specifying a JavaScript
     callback function. (Bertrand Delacretaz via yonik, SOLR-56)
 29. autoCommit can be specified every so many documents added (klaas, SOLR-65)
-    
+30. ${solr.home}/lib directory can now be used for specifying "plugin" jars
+    (hossman, SOLR-68)
+
 Changes in runtime behavior
  1. classes reorganized into different packages, package names changed to Apache
  2. force read of document stored fields in QuerySenderListener

Added: incubator/solr/trunk/example/solr/README.txt
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/example/solr/README.txt?view=auto&rev=474625
==============================================================================
--- incubator/solr/trunk/example/solr/README.txt (added)
+++ incubator/solr/trunk/example/solr/README.txt Mon Nov 13 18:05:32 2006
@@ -0,0 +1,36 @@
+Example "Solr Home" Directory
+=============================
+
+This directory is provided as an example of what a "Solr Home" directory
+should look like.
+
+It's not strictly necessary that you copy all of the files in this
+directory when setting up a new instance of Solr, but it is recommended.
+
+
+Basic Directory Structure
+-------------------------
+
+The Solr Home directory typically contains the following subdirectories...
+
+   conf/
+        This directory is mandatory and must contain your solrconfig.xml
+        and schema.xml.  Any other optional configuration files would also 
+        be kept here.
+
+   data/
+        This directory is the default location where Solr will keep your
+        index, and is used by the replication scripts for dealing with
+        snapshots.  You can override this location in the solrconfig.xml
+        and scripts.conf files. Solr will create this directory if it
+        does not already exist.
+
+   lib/
+        This directory is optional.  If it exists, Solr will load any Jars
+        found in this directory and use them to resolve any "plugins"
+        specified in your solrconfig.xml or schema.xml (ie: Analyzers,
+        Request Handlers, etc...)
+
+   bin/
+        This directory is optional.  It is the default location used for
+        keeping the replication scripts.

Propchange: incubator/solr/trunk/example/solr/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/solr/trunk/src/java/org/apache/solr/core/Config.java
URL: http://svn.apache.org/viewvc/incubator/solr/trunk/src/java/org/apache/solr/core/Config.java?view=diff&rev=474625&r1=474624&r2=474625
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/core/Config.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/core/Config.java Mon Nov 13 18:05:32 2006
@@ -33,6 +33,10 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Logger;
+import java.net.URLClassLoader;
+import java.net.URI;
+import java.net.URL;
+import java.net.MalformedURLException;
 
 /**
  * @author yonik
@@ -181,7 +185,7 @@
   private static final String[] packages = {"","analysis.","schema.","search.","update.","core.","request.","util."};
 
   public static Class findClass(String cname, String... subpackages) {
-    ClassLoader loader = Thread.currentThread().getContextClassLoader();
+    ClassLoader loader = getClassLoader();
     if (subpackages.length==0) subpackages = packages;
 
     // first try cname == full name
@@ -226,6 +230,7 @@
 
   public static void setInstanceDir(String dir) {
     instanceDir = normalizeDir(dir);
+    classLoader = null;
     log.info("Solr home set to '" + instanceDir + "'");
   }
 
@@ -249,6 +254,42 @@
     return getInstanceDir() + "conf/";
   }
 
+  /** Singleton classloader loading resources specified in any configs */
+  private static ClassLoader classLoader = null;
+  
+  /**
+   * Returns the singleton classloader to be use when loading resources
+   * specified in any configs.
+   *
+   * <p>
+   * This loader will delegate to the context classloader when possible,
+   * otherwise it will attempt to resolve resources useing any jar files
+   * found in the "lib/" directory in the "Solr Home" directory.
+   * <p>
+   */
+  static ClassLoader getClassLoader() {
+    if (null == classLoader) {
+      classLoader = Thread.currentThread().getContextClassLoader();
+      
+      File f = new File(getInstanceDir() + "lib/");
+      if (f.canRead() && f.isDirectory()) {
+        File[] jarFiles = f.listFiles();
+        URL[] jars = new URL[jarFiles.length];
+        try {
+          for (int j = 0; j < jarFiles.length; j++) {
+            jars[j] = jarFiles[j].toURI().toURL();
+            log.info("Adding '" + jars[j].toString() + "' to Solr classloader");
+          }
+          classLoader = URLClassLoader.newInstance(jars, classLoader);
+        } catch (MalformedURLException e) {
+          SolrException.log(log,"Can't construct solr lib class loader", e);
+        }
+      }
+    }
+    return classLoader;
+  }
+
+
   public static InputStream openResource(String resource) {
     InputStream is=null;
 
@@ -268,7 +309,7 @@
         }
       }
 
-      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      ClassLoader loader = getClassLoader();
       is = loader.getResourceAsStream(resource);
     } catch (Exception e) {
       throw new RuntimeException("Error opening " + resource, e);



plugin docs - was: Re: svn commit: r474625 - in /incubator/solr/trunk: CHANGES.txt example/solr/README.txt src/java/org/apache/solr/core/Config.java

Posted by Chris Hostetter <ho...@apache.org>.
FYI: I'll update the wiki to include some docs about this a little later
tonight, and then tomorow i'll send out mail to solr-user encouraging
people who currently "re-war" Solr to include custom code to please try it
out and let us know if there are any problems with it.


-Hoss