Unable to compile custom solr filter classes using javac

1k Views Asked by At

I am trying to build a jar for my custom filter in Solr 4.6. I am getting below error on running compile:

CustomFilter.java:19: error: package org.apache.lucene.analysis does not exist
import org.apache.lucene.analysis.TokenFilter;
                                 ^
CustomFilter.java:20: error: package org.apache.lucene.analysis does not exist
import org.apache.lucene.analysis.TokenStream;
                                 ^
CustomFilter.java:21: error: package org.apache.lucene.analysis.tokenattributes does not exist
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
                                                 ^
CustomFilter.java:24: error: package org.apache.solr.util does not exist
import org.apache.solr.util.NumberUtils;
                           ^
CustomFilter.java:43: error: cannot find symbol
public final class CustomFilter extends TokenFilter {
                                        ^
  symbol: class TokenFilter
CustomFilter.java:46: error: cannot find symbol
  private final CharTermAttribute termAtt = addAttribute(CharTermAttribute.class);
                ^
  symbol:   class CharTermAttribute
  location: class CustomFilter
CustomFilter.java:47: error: cannot find symbol
  private final PositionIncrementAttribute posIncrAtt = addAttribute(PositionIncrementAttribute.class);

I need some help regarding adding this custom filter to my schema. Without building this jar, I am getting below error on my solr admin if i try using the filter in the schema for a field:

 org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "textCustom": Plugin init failure for [schema.xml] analyzer/filter: Error instantiating class: 'org.apache.solr.analysis.Custom.CustomFilterFactory'. Schema file is /opt/solr5/collection3/schema.xml

There are duplicate questions to this but no correct answers. Hence please don't close this question on those basis.

1

There are 1 best solutions below

0
On

looks like you are trying to compile your class file without pointing to correct dependencies, make sure you are pointing the classpath to the directory that contains your plugin in this case: org.apache.lucene.analysis.TokenFilter (also check your other dependencies) i.e: lucene-1.3.jar is in the same directory as where is the java file

javac -cp:<directory> <file to compile>

javac -cp:. <file to compile> //period means classpath is same library to compile

Also make sure your custom tokenizer library is in the solr library. check your schema.xml for the existing libraries and add your custom solr filter library in the same directory.