Launching Solr from Maven for rapid development

If you are developing on top of Apache Solr, you might consider integration Solr with your maven build, by launching it from the maven-jetty-plugin. This brings several advantages, such as the possibility to shorten the time to get started in the project, unify the dev environment of the team with a fixed Solr version, do automated integration tests by launching and stopping Solr in the pre/post integration-test phase of the lifecycle and also creation of a single WAR contained the standard Solr with the custom plugins and configuration.

Here’s a way to do it:

1) Since solr.war is not yet available on public maven repo (SOLR-1218) make sure you deploy the solr.war file in any of your maven repo. In this post I’ll assume that solr.war is found inder org.apache.solr:solr-webapp:1.4.0 of you maven repo.

2) Use the maven webapp archetype to create an empty web project:

mvn archetype:generate

choose the maven-archetype-webapp option.

3) Change the pom.xml to:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.moreover</groupId>
  <artifactId>ubersearch</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>ubersearch Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
      <dependency>
        <groupId>org.apache.solr</groupId>
        <artifactId>solr-webapp</artifactId>
        <version>1.4.0</version>
        <type>war</type>
      </dependency>
  </dependencies>
  <build>
    <plugins>
       <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>maven-jetty-plugin</artifactId>
          <version>6.1.15.rc4</version>
       </plugin>
    </plugins>
  </build>
</project>

4) Copy the solr config files in the folder src/main/resources of the project. This will allow you to change them especifically for your project

$ ls src/main/resources/
elevate.xml            protwords.txt            solrconfig.xml            stopwords.txt
mapping-ISOLatin1Accent.txt    schema.xml            spellings.txt            synonyms.txt

5) Copy solr’s standard web.xml to the src/main/webapp/WEB-INF/ folder

6) Launch solr by calling the jetty plugin:

mvn jetty:run-exploded

7) Access Solr at http://localhost:8080/<artifactId>/admin/

Advertisements