I have to write my own custom request handler in solr but i am getting error like org.apache.solr.common.SolrException: Error loading class 'QPRequestHandler'
Here QPRequestHandler is my custom handler that i want to plug into my SOLR 3.4
Here is what i did so far:
Created new directory lib in apache-solr-3.4.0/example/solr/
In solrconfig.xml(path: apache-solr-3.4.0/example/solr/conf/solrconfig.xml) i have added this line
<lib dir="./lib" />
In solrconfig.xml i have added my custom handler like this:
<requestHandler name="/mytesthandler" class="QPRequestHandler"> <!-- initialization args may optionally be defined here --> <lst name="defaults"> <str name="d1">d1 value</str> </lst> <lst name="invariants"> <str name="i1">i1 value</str> </lst>
The sample code of QPRequestHandler is this:
public class QPRequestHandler extends RequestHandlerBase { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub } @Override public void init(NamedList args) { // do nothing } @Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.add("key1", "value1"); } }
I made a JAR file of this
QPRequestHandler.java
and put it in lib directory, path:apache-solr-3.4.0/example/solr/lib/
6 After restarting solr: i am getting error like org.apache.solr.common.SolrException: Error loading class 'QPRequestHandler'
Problem might be that i am creating jar file of java file and not the class file or is there any path issues or configuration error.
You would need to package the class into the jar file, which would be loaded by Solr.
You can compile the java file, by setting the classpath with the solr dependant jars.