设为首页 收藏本站
查看: 808|回复: 0

[经验分享] Building Solr as Maven Project

[复制链接]

尚未签到

发表于 2016-12-15 09:08:24 | 显示全部楼层 |阅读模式
  


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:


  • Create a Maven Project from eclipse using: File --> New --> Project...

    • Select Maven --> Maven Project from list
    • Check Create Simple Project
    • Specify some value in groupId and artifactId
    • Select Packaging type: war
    • Press Finish. This will create an empty maven project with basic folder structure in eclipse

  • 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>
  • 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
  • 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>
  • Run the solr using Run As --> Run configurations...

    • Specify jetty:run-exploded in Goals field and press Run


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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-314507-1-1.html 上篇帖子: Solr 学习(4) —- Solr数据导入 <二>SolrJ 下篇帖子: solr in action翻译- 第四章配置Solr 4.4
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表