在eclipse上搭建和运行solr项目

杀马特。学长 韩版系。学妹 提交于 2019-12-03 13:05:10

一、创建动态web项目

    由于maven比较麻烦,这里以web项目的形式在eclipse上运行

二、solr自带的war包目录结构

三、将以上内容copy到web项目webcontent下

四、修改web.xml

添加一个监听器用于加载solr索引地址

<listener>  
    <listener-class>  
        com.iflashbuy.solr.Solrlistener  
    </listener-class>  
</listener>



package com.iflashbuy.solr;

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) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * javax.servlet.ServletContextListener#contextInitialized(javax.servlet
	 * .ServletContextEvent)
	 */
	public void contextInitialized(ServletContextEvent sce) {

		String path = this.getClass().getResource("/").getPath();
//		int lastNum = path.lastIndexOf("WEB-INF/classes/");
//		path = path.substring(0, lastNum) + "solr";
		path = "D:/limanman/workspace/eclipse-luna/sgint_solr_server/WebContent/home/collection1";//jetty会报错 所以我直接写死了这个路径
		System.setProperty("solr.solr.home", path);
	}

}



五、在上述步骤所指定的索位置添加相关索引目录

六、运行项目并访问http://localhost:8993/solr


当然你也可以通过eclipse在tomcat运行个人习惯而已。


七、初始化索引目录

上述图片中默认data文件夹和core.properties是没有的,通过访问http://localhost:8993/solr,在控制台添加对应索引,索引名称和对应文件夹名称相同接口。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!