eclipse下将solr发布为web项目

仍然使用Solr-4.9.1版本,由于在eclipse中操作比较方便,所以将solr在eclipse中发布为web项目,便于后续添加代码,创建solr的web项目步骤如下:

1、Solr-demo:在eclipse中新建web项目,命名为solr-demo

2、Solr_home:将solr.war(solr解压目录的example/webapps)放在tomcatwebapps下,然后启动tomcat,可以解压solr.war,取得solr为名的项目目录,然后将solr目录下的所有文件拷贝到solr-demo\WebContent下,命名为solr_home(注意有相同文件METE-INFWEB-INFWEB-INF下包含solr需要的jar包和web.xmlsolr的配置,需要保留)

切记:在tomcat启动之前不要创建其他的core文件夹,尤其注意除了默认的collection1,在其他文件夹下不要包含core.properties文件,否则会导致tomcat启动失败

配置文件中配置找寻solr_home的路径(我在此处在solr_home下又加了一层collection1路径(此路径不作为core的名称),在collection1下可以创建collection1、usercore)

配置寻找solr_home路径两种方式:

i、web.xml中配置

<env-entry>

       <env-entry-name>solr/home</env-entry-name>   <env-entry-value>D:/workspace/solr-demo/WebContent/solr_home/collection1</env-entry-value>

       <env-entry-type>java.lang.String</env-entry-type>

    </env-entry>

ii、listener配置

web.xml中加入监听器配置

<listener>  

    <listener-class>  

        solr.common.SolrListener  

    </listener-class>  

</listener>

编写SolrListener,目录在solr.common(src/main/java)

package solr.common;

import javax.servlet.ServletContextEvent;

import javax.servlet.ServletContextListener;

/**

 * 通过监听器设置solr.solr.home,需要在web.xml配置

 * @author limanman

 *

 */

public class SolrListener implements ServletContextListener {

/*

 * (non-Javadoc)

 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.

 * ServletContextEvent)

 */

public void contextDestroyed(ServletContextEvent sce) {

}

/*

 * (non-Javadoc)

 * @see

 * javax.servlet.ServletContextListener#contextInitialized(javax.servlet

 * .ServletContextEvent)

 */

public void contextInitialized(ServletContextEvent sce) {

String path = this.getClass().getResource("/").getPath();

path = "D:/workspace/solr-demo/WebContent/solr_home/collection1";//jetty会报错 所以我直接写死了这个路径

System.setProperty("solr.solr.home", path);

}

}

3、补充:然后按照单机版的tomcat服务配置补充文件,将solr-4.9.1\example\lib\ext文件夹下的jar包拷贝到WEB-INFlib目录下(注:必须放在此目录下,否则找不到jar),将example/resource下的log4j.properties复制到项目的resource目录中

4、启动tomcat,运行URL:http://localhost:8080/solr-demo/admin.html  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值