user1282820
user1282820

Reputation: 11

Solr setup on Tomcat 7 (with Eclipse)

i have configured solr on tomcat 7 in windows so when i manually start tomcat server and when i hit the solr it searches very well in my browser.

and when i write a java class with main method as follows the results are fetched and shown on console.

public class Code{
public static void main(String[] args) throws MalformedURLException, SolrServerException {
SolrServer solr = new CommonsHttpSolrServer("http://192.168.16.221:8080/solr");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "subhash");

System.out.println("response = " + params);
QueryResponse response = solr.query(params);
System.out.println("response = " + response);
}
}

But when i use the same code in method and call this method using its object this error is shown

java.lang.NoClassDefFoundError: org/apache/solr/client/solrj/SolrServerException

Eagerly waiting for your reply.

Upvotes: 0

Views: 385

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20882

You need to use the "-classpath" command-line option to "java" in order to tell it where all the libraries you need are living. The default CLASSPATH includes only the system classes, etc.

So, if you have your Code.class file in the current directory along with solr-x.y.z.jar, then you need to do something like this:

$ java -classpath .:solr-x-y-z.jar Code

I would be surprised if Solr didn't have a bunch of its own dependencies, meaning that you will need to include a bunch of JAR files in your -classpath similar to above.

This is Java 101.

Upvotes: 1

Related Questions