在嵌入式Jetty中运行Solr的异常

时间:2013-09-05 16:08:36

标签: java solr lucene jetty classcastexception

我在嵌入式Jetty中运行Solr 4.4.0但是我得到了以下异常:

3859 [coreLoadExecutor-3-thread-1] ERROR org.apache.solr.core.CoreContainer - null:java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:266)
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:433)
at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:543)
at org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
at org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:86)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:467)
at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:164)
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.CoreContainer.createFromLocal(CoreContainer.java:619)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:657)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:364)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:356)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
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:722)
Caused by: java.lang.ClassCastException: class org.apache.lucene.analysis.ar.ArabicNormalizationFilterFactory
at java.lang.Class.asSubclass(Class.java:3046)
at org.apache.lucene.util.SPIClassIterator.next(SPIClassIterator.java:137)
at org.apache.lucene.analysis.util.AnalysisSPILoader.reload(AnalysisSPILoader.java:79)
at org.apache.lucene.analysis.util.AnalysisSPILoader.<init>(AnalysisSPILoader.java:60)
at org.apache.lucene.analysis.util.AnalysisSPILoader.<init>(AnalysisSPILoader.java:49)
at org.apache.lucene.analysis.util.TokenFilterFactory.<clinit>(TokenFilterFactory.java:31)
... 27 more

这是Java代码的主要方法:

public static void main(String[] args) throws Exception
{
    Server server = new Server(8083);
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar("C:\\Solr\\solr-4.4.0.war");
    server.setHandler(webapp);
    System.setProperty("solr.solr.home", "C:\\solr");
    server.start();
    server.join();
}

我们正在使用schema.xml中声明的自定义字段类型(它没有此字段类型):

<fieldType name="zyfield" class="solr.TextField" positionIncrementGap="0" >
<analyzer type="index">
    <!--<tokenizer class="solr.PatternTokenizerFactory" pattern="([\.0-9]+|@??[&amp;'a-zA-Z_0-9-]+(\.(net|ie|uk|com|txt))?)" group="1"/>-->
    <tokenizer class="solr.PatternTokenizerFactory" pattern="(www|@??[-0-9\p{L}\p{Sc}]+?[-'0-9.\p{L}\p{Sc}&amp;]*[-0-9\p{L}]+?|[-0-9\p{L}\p{Sc}]+?)" group="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="ie.solrplugin.KDelimiterFilterFactory"/>
    <filter class="ie.solrplugin.JunkTokenFilterFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory"/>
</analyzer>
<analyzer type="query">
    <tokenizer class="solr.PatternTokenizerFactory" pattern="(www|@??[-0-9\p{L}\p{Sc}]+?[-'0-9.\p{L}\p{Sc}&amp;]*[-0-9\p{L}]+?|[-0-9\p{L}\p{Sc}]+?)" group="1"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="ie.solrplugin.KDelimiterFilterFactory"/>
    <filter class="ie.solrplugin.JunkTokenFilterFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory"/>
</analyzer>

1 个答案:

答案 0 :(得分:1)

您可能会在运行main方法的项目的类路径与所有WebApp的类加载器隔离之间产生复杂性。

尝试添加此项以告知WebAppContext使用WebApp自己的父类加载器。

public static void main(String[] args) throws Exception
{
    Server server = new Server(8083);
    WebAppContext webapp = new WebAppContext();
    webapp.setContextPath("/");
    webapp.setWar("C:\\Solr\\solr-4.4.0.war");
    webapp.setParentLoaderPriority(true);     // <-- this line
    server.setHandler(webapp);
    System.setProperty("solr.solr.home", "C:\\solr");
    server.start();
    server.join();
}