How to run SolR in maven for tests that need to do some searches

Here’s a Maven pom section that launches Jetty instance with Apache SolR deployed just before tests and stops it after integration tests are finished.
You can select what what war will be deployed and where will be SolR home located (of course you need to prepare it first).
Hope you find it useful:

                                                                                                                       
<plugin>                                                                                                               
    <groupId>org.mortbay.jetty</groupId>                                                                               
    <artifactId>jetty-maven-plugin</artifactId>                                                                        
    <version>8.1.8.v20121106</version>                                                                                 
    <configuration>                                                                                                    
        <!--Need empty war tag so contextHandlers are loaded with Solr on proper path-->                               
        <war></war>                                                                                                    
        <jvmArgs>-Xmx2048m</jvmArgs>                                                                                   
        <systemProperties>                                                                                             
            <systemProperty>                                                                                           
                <name>solr.solr.home</name>                                                                            
                <value>${project.build.directory}/solr</value>                                                         
            </systemProperty>                                                                                          
        </systemProperties>                                                                                            
        <connectors>                                                                                                   
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">                           
                <port>8983</port>                                                                                      
            </connector>                                                                                               
        </connectors>                                                                                                  
        <contextHandlers>                                                                                              
            <contextHandler implementation="org.mortbay.jetty.plugin.JettyWebAppContext">                              
                <war>${project.build.directory}/solr-${solr.version}.war</war>                                         
                <contextPath>/solr</contextPath>                                                                       
            </contextHandler>                                                                                          
        </contextHandlers>                                                                                             
    </configuration>                                                                                                   
    <executions>                                                                                                       
        <execution>                                                                                                    
            <id>start-jetty</id>                                                                                       
            <phase>process-test-classes</phase>                                                                        
            <goals>                                                                                                    
                <goal>deploy-war</goal>                                                                                
            </goals>                                                                                                   
            <configuration>                                                                                            
                <scanIntervalSeconds>0</scanIntervalSeconds>                                                           
                <daemon>true</daemon>                                                                                  
                <stopKey>stop</stopKey>                                                                                
                <stopPort>9999</stopPort>                                                                              
            </configuration>                                                                                           
        </execution>                                                                                                   
        <execution>                                                                                                    
            <id>stop-jetty</id>                                                                                        
            <phase>post-integration-test</phase>                                                                       
            <goals>                                                                                                    
                <goal>stop</goal>                                                                                      
            </goals>                                                                                                   
            <configuration>                                                                                            
                <stopKey>stop</stopKey>                                                                                
                <stopPort>9999</stopPort>                                                                              
            </configuration>                                                                                           
        </execution>                                                                                                   
    </executions>                                                                                                      
    <dependencies>                                                                                                     
        <dependency>                                                                                                   
            <groupId>org.eclipse.jetty</groupId>                                                                       
            <artifactId>jetty-rewrite</artifactId>                                                                     
            <version>8.1.8.v20121106</version>                                                                         
        </dependency>                                                                                                  
        <dependency>                                                                                                   
            <groupId>org.slf4j</groupId>                                                                               
            <artifactId>slf4j-log4j12</artifactId>                                                                     
            <version>1.6.1</version>                                                                                   
            <type>jar</type>                                                                                           
        </dependency>                                                                                                  
        <dependency>                                                                                                   
            <groupId>log4j</groupId>                                                                                   
            <artifactId>log4j</artifactId>                                                                             
            <version>1.2.14</version>                                                                                  
            <type>jar</type>                                                                                           
        </dependency>                                                                                                  
    </dependencies>                                                                                                    
</plugin>                                                                                                              
About these ads

2 Responses to How to run SolR in maven for tests that need to do some searches

  1. The best hosts well in addition maintain fast bandwidth and are used to deal with several
    technical problems that can take place. If you are thinking of how you cann improve your business and increase profits without the many hassles, go and setup your website.

    If you are doing websites created in ASP then you
    have to make sufe that you are using a Windows hosting account and not Linux.

  2. This piece of writing is truly a fastidious one it helps new internet
    viewers, who are wishing for blogging.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: