0

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

MrLang
  • 629
  • 1
  • 6
  • 15
  • possible your path is wrong. Copy your lib folder in same parent-folder as `solrconfig.xml` and use `dir="lib"`: https://cwiki.apache.org/confluence/display/solr/Lib+Directives+in+SolrConfig – Karsten R. Jan 20 '16 at 13:02
  • thanks for the answer. I tried, but I still get: `org.apache.solr.common.SolrException: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` – MrLang Jan 21 '16 at 13:18
  • Please copy and rename an existing filter to your jar-file and try to access it form solr. Possible your "SplitOnPatternFilterFactory"-Class has a problem with a static constructor? http://stackoverflow.com/questions/6352215/java-why-java-lang-noclassdeffounderror-caused-by-static-field-initializ-failur – Karsten R. Jan 22 '16 at 08:45

2 Answers2

1

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>
freedev
  • 25,946
  • 8
  • 108
  • 125
  • Thanks for the answer, but when i try this i get: `java.lang.NullPointerException at org.apache.solr.servlet.SolrDispatchFilter.authenticateRequest(SolrDispatchFilter.java:241) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:186) at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:179) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)` – MrLang Jan 21 '16 at 12:09
  • after fixing a syntax error, I still get: `org.apache.solr.common.SolrException: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` any idea what I could try? – MrLang Jan 21 '16 at 13:17
  • Try using absolute path when specifying where are your libraries. And be sure all dependencies are satisfied. – freedev Jan 21 '16 at 13:20
  • To get this answer working for me I needed to change it to an absolute path. `${solr.install.dir}/opt/shared-lib` – Gnietschow Feb 28 '23 at 15:17
0

In Windows solr.xml may look like this:

<solr>
  <str name='sharedLib'>F:\solr_deployment\solr-7.6.0\contrib\analysis-extras\lucene-libs</str>

  <solrcloud>

    <str name="host">${host:}</str>
    <int name="hostPort">${jetty.port:8983}</int>
    <str name="hostContext">${hostContext:solr}</str>

    <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>

    <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
    <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>
    <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>
    <str name="zkCredentialsProvider">${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider}</str>
    <str name="zkACLProvider">${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider}</str>

  </solrcloud>

  <shardHandlerFactory name="shardHandlerFactory"
    class="HttpShardHandlerFactory">
    <int name="socketTimeout">${socketTimeout:600000}</int>
    <int name="connTimeout">${connTimeout:60000}</int>
  </shardHandlerFactory>

</solr>

Alternatively, one may have this in solrconfig.xml file:

<config>
        <luceneMatchVersion>7.6.0</luceneMatchVersion>

        <lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-analysis-\d.*\.jar" />
...
</config>
arthur
  • 1,034
  • 2
  • 17
  • 31