因爲maven比較麻煩,這裏以web項目的形式在eclipse上運行 java
添加一個監聽器用於加載solr索引地址 web
<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); } }
固然你也能夠經過eclipse在tomcat運行我的習慣而已。 tomcat
上述圖片中默認data文件夾和core.properties是沒有的,經過訪問http://localhost:8993/solr,在控制檯添加對應索引,索引名稱和對應文件夾名稱相同接口。 eclipse