一、创建动态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,在控制台添加对应索引,索引名称和对应文件夹名称相同接口。