转自:http://www.cnblogs.com/jeniss/p/5995921.html
最近在使用solr时,配置会有一些问题,log里面打印出日志了,但是还是不知道发生这样错误的原因。于是想学习一下相关的solr源码,以下是如何搭建solr调试环境步骤。
solr调试环境搭建,首先下载源码。
可以通过 http://archive.apache.org/dist/lucene/solr/ 下载各个版本的源码。还可以在github下载最新的solr代码,地址是:https://github.com/jeniss/lucene-solr。
源码导入Intellij idea
在下载后的solr项目,可以发现是用ant管理的。所以需要确保已安装ant。ant下载地址:http://ant.apache.org/bindownload.cgi。在环境变量中配置ant。ANT_HOME:D:\Program Files (x86)\java\apache-ant-1.9.7,Path:%ANT_HOME%\bin。配置完成后,执行ant -version,显示ant版本,则代表安装成功。如图。

接下来,solr源码编译为idea的项目。
在根目录下,运行ant命令,查看ant可以执行的操作。

当我们执行ant idea,即可将solr源码编译成intellij idea的项目。在编译ant idea时候可能会失败,这是可以运行 ant ivy-bootstrap。
编译成功后,在intellij idea中通过open的方式导入。选择“lucene-solr”父项目后,项目会整体导入。
->


此时,项目导入intellij idea。
配置JDPA远程调试
从5.3开始,solr不再提供war包。solr团队说:“Solr is intended to be aservernot aJava web application”。因此,在\lucene-solr\solr目录下,运行ant server创建solr server。solr的cores默认的根目录为\lucene-solr\solr\server\solr。
然后,在idea配置远程调试。在“Run Configurations”里添加Remote,在配置中,自定义Name,Host,和Port。Transport选择socket选项。

接着,我们在cmd中进入lucene-solr\solr\bin文件夹中,运行solr start -p 8988 -f -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8988",配置的端口号(e.g. 8988)要与在idea中配置的端口号一致。
最后,在idea中运行debug模式。我们在网页中http://localhost:8988,则可以开始进行调试。
在Intellij idea中查看solr日志文件
为了更方便的查看solr日志文件,可以进行如下配置在idea中查看日志。
在Debug Configurations中添加\lucene-solr\solr\server\logs\solr.log文件。

修改\lucene-solr\solr\server\resources\log4j.properties文件,自定义日志输出的内容。在远程调试时,idea中显示的日志如下:
