Search code examples
solrsolrj

Adding my own classes to solr 5.3.1


I want to update my solr based application from Solr 4 to Solr 5.3.1

I just found out, since Solr 5.2 it is no longer possible to run Solr as a WebApp. So instead of packaging the project (with solr as Maven dependencies) as a WAR and running it with a separate Jetty, now I need to put my source code into the Solr. But how can i do this?

I tried to package my project as a JAR and put it in the folder /solr-5.3.1/contrib/mySearchApplication/lib/mysearch.jar and I added this path in solrconfig.xml <lib dir="${solr.install.dir:../../../..}/contrib/mySearchApplication/lib" regex=".*\.jar" /> but when I try to run Solr it still can't find my Classes, e.g. my customized token filters.

So how can I add my java classes to solr?

I get this error message:

ERROR (coreLoadExecutor-6-thread-1) [ ] o.a.s.c.CoreContainer Error creating core [myCollection]: Could not load conf for core myCollection: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml org.apache.solr.common.SolrException: Could not load conf for core myCollection: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml at org.apache.solr.core.ConfigSetService.getConfig(ConfigSetService.java:80) at org.apache.solr.core.CoreContainer.create(CoreContainer.java:721) at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:443) at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:434) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor$1.run(ExecutorUtil.java:210) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:596) at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:175) at org.apache.solr.schema.IndexSchemaFactory.create(IndexSchemaFactory.java:55) at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:69) at org.apache.solr.core.ConfigSetService.createIndexSchema(ConfigSetService.java:104) at org.apache.solr.core.ConfigSetService.getConfig(ConfigSetService.java:75) ... 8 more


Solution

  • You can add the sharedLib parameter into the solr.xml file.

    This parameter specifies the path to a common library directory that will be shared across all cores. Any JAR files in this directory will be added to the search path for Solr plugins. This path is relative to the top-level container's Solr Home.

    Here is how I did.

    <?xml version='1.0' encoding='UTF-8'?>
    <solr>
          <str name='sharedLib'>/opt/shared-lib</str>
    
          <solrcloud>
              <str name="host">${host:}</str>
              <int name="hostPort">${hostPort:8080}</int>
              <str name="hostContext">${hostContext:solr}</str>
              <int name="zkClientTimeout">${zkClientTimeout:15000}</int>
              <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
          </solrcloud>
    
          <shardHandlerFactory name="shardHandlerFactory"
              class="HttpShardHandlerFactory">
              <int name="socketTimeout">${socketTimeout:0}</int>
              <int name="connTimeout">${connTimeout:0}</int>
          </shardHandlerFactory>
    
    </solr>