`
lionelf
  • 浏览: 81542 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Building Solr as Maven Project

    博客分类:
  • JAVA
 
阅读更多

Building Solr as Maven Project

Now days maven is most commonly used build tool. But solr still uses ant build. In this article I am going to describe how you can quickly create Solr Maven Project and run solr using jetty.

Solr war is available in Maven Central repository(http://mvnrepository.com/artifact/org.apache.solr/solr).

Steps to build Solr Maven Project:

  1. Create a Maven Project from eclipse using: File --> New --> Project...
    1. Select Maven --> Maven Project from list
    2. Check Create Simple Project
    3. Specify some value in groupId and artifactId
    4. Select Packaging type: war
    5. Press Finish. This will create an empty maven project with basic folder structure in eclipse
  2. Now Edit pom.xml and update it with below content:
    <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/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <groupId>org.apache.mysolr</groupId>
     <artifactId>mysolr</artifactId>
     <version>3.4.0</version>
     <packaging>war</packaging>
     <name>Apache Solr Web Application</name>
     <repositories>
       <repository>
         <id>central</id>
         <name>Maven Repository Switchboard</name>
         <layout>default</layout>
         <url>http://repo1.maven.org/maven2</url>
       </repository>
     </repositories>
     <pluginRepositories>
       <pluginRepository>
         <id>central</id>
         <name>Maven Plugin Repository</name>
         <url>http://repo1.maven.org/maven2</url>
         <layout>default</layout>
       </pluginRepository>
     </pluginRepositories>
     <dependencies>
         <dependency>
           <groupId>org.apache.solr</groupId>
           <artifactId>solr</artifactId>
           <version>3.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>
    
  3. Copy the solr config files in the folder src/main/resources of the project.
    solrconfig.xml
    schema.xml
    elevate.xml
    protwords.txt
    stopwords.txt
    spellings.txt
    synonyms.txt
    
  4. Copy the default solr web.xml content from below to src/main/webapp/WEB-INF/web.xml
    
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
     contributor license agreements.  See the NOTICE file distributed with
     this work for additional information regarding copyright ownership.
     The ASF licenses this file to You under the Apache License, Version 2.0
     (the "License"); you may not use this file except in compliance with
     the License.  You may obtain a copy of the License at
    
         http://www.apache.org/licenses/LICENSE-2.0
    
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
    -->
    
    <web-app>
     
      <!-- Uncomment if you are trying to use a Resin version before 3.0.19.
        Their XML implementation isn't entirely compatible with Xerces.
        Below are the implementations to use with Sun's JVM.
      <system-property javax.xml.xpath.XPathFactory=
                 "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl"/>
      <system-property javax.xml.parsers.DocumentBuilderFactory=
                 "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"/>
      <system-property javax.xml.parsers.SAXParserFactory=
                 "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"/>
       -->
    
      <!-- People who want to hardcode their "Solr Home" directly into the
           WAR File can set the JNDI property here...
       -->
      <!--
        <env-entry>
           <env-entry-name>solr/home</env-entry-name>
           <env-entry-value>/put/your/solr/home/here</env-entry-value>
           <env-entry-type>java.lang.String</env-entry-type>
        </env-entry>
       -->
       
      <!-- Any path (name) registered in solrconfig.xml will be sent to that filter -->
      <filter>
        <filter-name>SolrRequestFilter</filter-name>
        <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
        <!-- If you are wiring Solr into a larger web application which controls
             the web context root, you will probably want to mount Solr under
             a path prefix (app.war with /app/solr mounted into it, for example).
             You will need to put this prefix in front of the SolrDispatchFilter
             url-pattern mapping too (/solr/*), and also on any paths for
             legacy Solr servlet mappings you may be using.
             For the admin JSP's to work properly in a path-prefixed configuration,
             the admin folder containing the JSPs needs to be under the app context root
             named to match the path-prefix.  For example:
    
                .war
                   xxx
                     admin
                       stats.jsp
        -->
        <!--
        <init-param>
          <param-name>path-prefix</param-name>
          <param-value>/xxx</param-value>
        </init-param>
        -->
      </filter>
    
      <filter-mapping>
        <!--
          NOTE: When using multicore, /admin JSP URLs with a core specified
          such as /solr/coreName/admin/stats.jsp get forwarded by a
          RequestDispatcher to /solr/admin/stats.jsp with the specified core
          put into request scope keyed as "org.apache.solr.SolrCore".
    
          It is unnecessary, and potentially problematic, to have the SolrDispatchFilter
          configured to also filter on forwards.  Do not configure
          this dispatcher as <dispatcher>FORWARD</dispatcher>.
        -->
        <filter-name>SolrRequestFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <!-- Otherwise it will continue to the old servlets -->
      
      <servlet>
        <servlet-name>SolrServer</servlet-name>
        <display-name>Solr</display-name>
        <description>Solr Server</description>
        <servlet-class>org.apache.solr.servlet.SolrServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet>
        <servlet-name>SolrUpdate</servlet-name>
        <display-name>SolrUpdate</display-name>
        <description>Solr Update Handler</description>
        <servlet-class>org.apache.solr.servlet.SolrUpdateServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
      </servlet>
    
      <servlet>
        <servlet-name>Logging</servlet-name>
        <servlet-class>org.apache.solr.servlet.LogLevelSelection</servlet-class>
      </servlet>
    
      <!-- @Deprecated -->
      <servlet>
        <servlet-name>ping</servlet-name>
        <jsp-file>/admin/ping.jsp</jsp-file>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>SolrServer</servlet-name>
        <url-pattern>/select/*</url-pattern>
      </servlet-mapping>
    
      <servlet-mapping>
        <servlet-name>SolrUpdate</servlet-name>
        <url-pattern>/update/*</url-pattern>
      </servlet-mapping>
    
      <servlet-mapping>
        <servlet-name>Logging</servlet-name>
        <url-pattern>/admin/logging</url-pattern>
      </servlet-mapping>
    
      <!-- @Deprecated -->
      <servlet-mapping>
        <servlet-name>ping</servlet-name>
        <url-pattern>/admin/ping</url-pattern>
      </servlet-mapping>
    
      <!-- @Deprecated -->
      <servlet-mapping>
        <servlet-name>Logging</servlet-name>
        <url-pattern>/admin/logging.jsp</url-pattern>
      </servlet-mapping>
      
      <mime-mapping>
        <extension>.xsl</extension>
        <!-- per http://www.w3.org/TR/2006/PR-xslt20-20061121/ -->
        <mime-type>application/xslt+xml</mime-type>
      </mime-mapping>
    
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
      </welcome-file-list>
    
    </web-app>
    
    

  5. Run the solr using Run As --> Run configurations...
    • Specify jetty:run-exploded in Goals field and press Run

  6. Access Solr at http://localhost:8080/<artifactId>/admin/
分享到:
评论

相关推荐

    solr-maven-plugin:一个用于停止Apache Solr Cloud的Maven插件

    Solr-Maven插件 一个用于启动/停止Apache Solr Cloud的Maven插件。 安装 在Maven Central上可用的发行版 &lt; groupId&gt;io.github.borisnaguet &lt; artifactId&gt;solr-maven-plugin &lt; version&gt;0.5.0 Sonatype信息库中...

    maven 搭建solr4.2源码环境

    maven 整合solr4.2环境,另外整合了solr-data-import源码环境,资源10分,十分不贵!有需要的朋友请下载吧。花了我3个小时的时间整理的。下载后,使用maven导入即可使用,升级solr版本也比较方便。本环境使用了...

    solr ssm java

    自己弄的一个maven项目 框架ssm 改改配置就能用 搭建文档我已经加到了压缩包 有不懂的可以问 windows下搭建的solr 跟linux步骤差不多

    solr.4.9.1

    solr.4.9.1 solr.4.9.1

    solr+spring+hibernate+maven+webservice整合框架

    这个主要是整合了solr的spring+hibernate+webservice的一个框架代码,给大家讲解了solr的批次汇入和增删改查方法的实现方式,给初学者一些代码参考,希望能够帮助大家

    ssm+shiro+solr7+mybatis逆向+maven多项目初步搭建测试

    几乎全新搭建ssm+shiro+solr7+mybatis逆向+maven多项目初步搭建测试,只是大致框架,接下来自己写,下面是linux 下solr7+tomcat8+IK中文分词器 环境 https://download.csdn.net/download/laysolitary/10686971

    solr.war包solr.war包solr.war包solr.war包solr.war包

    solr.warsolr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包...

    maven-solr-webapp:一个运行 solr webapp 的 Maven 快速入门项目

    maven-solr-webapp 一个用于运行 solr webapp 的 Maven 快速入门项目。 这个 maven 项目包括一个 solr-webapp (war) 和配置文件,用于快速启动和运行 solr 实例。 solr webapp 是通过以下方式启动的 mvn tomcat7:...

    利用Solr搭建你的搜索引擎

    NULL 博文链接:https://kunkun39.iteye.com/blog/1765564

    solr服务器_solr_

    solr

    solr-mvn-template:用于设置和部署 Solr 服务器的示例 Maven 模板

    Solr Maven 模板 阿拉斯泰尔·波特,2013 此示例 POM 提供了一种简单的方法来开发 Solr 服务器,然后将其部署到 servlet 容器。 发展 要快速设置 solr 服务器,请运行 mvn jetty:run-war 在访问 solr 服务器 Solr ...

    solr

    solr

    confit-api-model-0.17.0.zip

    solr-maven-plugin.zip,apache solr maven插件在集成测试期间运行apachesolr实例

    solr文档solr文档

    solr文档

    solr基础知识介绍

    7.2.1 Maven 20 7.3 HttpSolrServer 21 7.3.1 Changing other Connection Settings 22 7.4 EmbeddedSolrServer 22 7.5 Usage 23 7.5.1 Adding Data to Solr 23 7.5.2 Setting the RequestWriter 32 7.5.3 Reading ...

    Solr in Action_2014

    Solr in Action by Trey Grainger , Timothy Potter Book Description ... - Solr as a NoSQL data store - Advanced multilingual, data, and relevancy tricks - Coverage of versions through Solr 4.7

    solr_solr_

    solr manageschema 配置文件,增加了分词器后的配置文件

    solr技术文solr技术文

    solr技术文solr技术文solr技术文

    Solr in Action最新完整版

    DESCRIPTION Whether handling big data, building cloud-based services, or developing multi-tenant web applications, it's vital to have a fast, reliable search solution. Apache Solr is a scalable and ...

    solr-7.7.1

    Solr是一个独立的企业级搜索应用服务器,基于Lucene。其主要功能包括全文检索、命中标示、分面搜索、动态聚类、数据库集成,以及富文本(如Word、PDF)的处理。它可对外提供类似于Web-service的API接口。用户可以...

Global site tag (gtag.js) - Google Analytics