Apache Solr and SolrJ Maven Dependancies

While I was developing Solr application using Solrj, there was confusion (which is always :) ) of which maven dependencies to be included in Pom.xml. Hence thought to share here.
Please don't miss to add M2_REPO classpath variable pointing to repository directory so you can easily import required library into your Java Project.

Maven Dependencies for Developing application with Solr (version 4.1) are followed as :

1. Solrj Dependencies
<dependency>
           <artifactId>solr-solrj</artifactId>
           <groupId>org.apache.solr</groupId>
           <version>4.1.0</version>
           <type>jar</type>
    </dependency>

2. Solr-core Dependencies
<dependency>
           <artifactId>solr-core</artifactId>
           <groupId>org.apache.solr</groupId>
           <version>4.1.0</version>
           <type>jar</type>
    </dependency>
    <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>servlet-api</artifactId>
           <version>2.5</version>
    </dependency>


Servlet-api required because EmbeddedSolrServer is dependent on servlet-api. Please include in Maven if you are planning to add into your project

3. Sl4j Dependencies
<dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.2</version>
    </dependency>

4. HttpClient Dependencies
<!-- httpClient dependencies -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpmime</artifactId>
        <version>4.2.1</version>
    </dependency>

5. JUnit Dependencies
<!-- Junit Depedencies -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

Maven Compiler Plugins for POM.xml are :
<build>
      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
      </plugins>
    </build>

Once You added all required dependencies and plugins to pom.xml it's time to Compile project

1.Convert your project to eclipse project with mvn eclipse:eclipse
2.Compile your Project with mvn compile
3.Clean your Project with mvn eclipse:clean or mvn clean

Note : Please refer to http://lucene.apache.org/ and Apache License before using.


No comments:

Post a Comment