2

I am a newbie in Solr and maven and i want to make a small application that index all my database tables via SolrJ .
For that i looked up at this tutorial where they are using MAVEN .
I installed the librairies and jars (except maven) but i had this exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor

I looked into the tutorial and i saw that for resolving this problem we need to add this to my maven configuration:

org.slf4j slf4j-simple 1.5.6

Is there anyway to do that without maven? Thank you

Bourkadi
  • 738
  • 1
  • 7
  • 17

2 Answers2

2

Use maven. Even with it, it took me a fairly considerable amount of time to get the dependencies right. The tutorials were all a bit lacking. Below is my pom.xml with the relevant dependencies that I had maven bring in. Perhaps it will help you.

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-core</artifactId>
    <version>4.3.0</version>
</dependency>
<dependency>
    <artifactId>solr-solrj</artifactId>
    <groupId>org.apache.solr</groupId>
    <version>4.3.0</version>
    <type>jar</type>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>
Mike Nitchie
  • 1,166
  • 2
  • 13
  • 29
  • Wow, why commons-logging needs to be added explicitly rather than discovering the dependency is beyond me. But that solved the problem I had. Thanks! – Brandon Feb 25 '16 at 01:18
  • why do we need to add solr-core dependency doesn't it works only with solr-sorlj – userab Jun 14 '17 at 12:58
0

Maven is the suggested build technology for the Solrj, because it automates the management of 3rd party dependencies. Without dependency management it's a royal pain to decipher these relationships (Jar hell).

What I could suggest is to use ivy, which has a command-line mode.

First download the ivy jar

To retrieve the following Maven module and all it's dependencies:

    <dependency>
           <artifactId>solr-solrj</artifactId>
           <groupId>org.apache.solr</groupId>
           <version>1.4.0</version>
           <type>jar</type>
           <scope>compile</scope>
    </dependency>

Then run it as follows:

 java -jar ivy.jar \
      -dependency org.apache.solr solr-solrj 1.4.0 \
      -retrieve "lib/[artifact]-[revision](-[classifier]).[ext]" \
      -confs default

Retrieves into the lib directory:

lib/commons-httpclient-3.1.jar
lib/wstx-asl-3.2.7.jar
lib/slf4j-api-1.5.5.jar
lib/commons-codec-1.3.jar
lib/stax-api-1.0.1.jar
lib/geronimo-stax-api_1.0_spec-1.0.1.jar
lib/commons-logging-1.0.4.jar
lib/solr-solrj-1.4.0.jar
lib/commons-io-1.4.jar
lib/commons-fileupload-1.2.1.jar

Update

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor

This is due to a missing httpcore.jar file. I found this out by browsing Maven Central:

The recommendation on using the "slf4j-simple" is to provide a logging implementation in case your application doesn't have one.

Finally... This demonstrates what I've tried to say. In the absence of a dependency management tool (ivy, groovy, Maven) you're on your own in deciphering the 3rd party jar dependencies.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • in another term: can i use solrj without installing maven? i can manage my jars by myself because i'm not used to work with maven – Bourkadi Jan 23 '13 at 12:05
  • 1
    @mohammedaminebourkadi Solrj is a Java library. Of course you can manage the jars yourself. Problem is it's up to you figure out how Maven is managing the dependencies between jars. What I offered in my answer was a mechanism to do the jar download automatically (Saves time and keeps blood pressure low) – Mark O'Connor Jan 23 '13 at 13:03
  • When i added the mentionned librairies to my lib folder and added it to my build path and i run a test example i had this error: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpRequestInterceptor – Bourkadi Jan 23 '13 at 16:25
  • and in the tutorial they said if you get this error then you have to add this :If you see any exceptions saying NoClassDefFoundError, you will also need to include: org.slf4j slf4j-simple 1.5.6 – Bourkadi Jan 23 '13 at 16:39
  • I've added all the librairies mentionned above but it's still not working? what can i do? – Bourkadi Jan 28 '13 at 14:09