首页 > 代码库 > Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建
Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建
Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建
由于公司里的Solr调试都是用远程jpda进行的,但是家里只有一台电脑所以不能jpda进行调试,这是因为jpda的端口冲突。所以只能在Eclipse 搭建Solr的环境,折腾了一小时终于完成了。
1. JDPA远程调试
搭建换完成Solr环境后,对${TOMCAT_HOME}/bin/startup.sh 最后一行进行修改,如下所示:
1 set JPDA_ADDRESS=70702 exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"
后在eclipse新建debug配置,这样就可以远程调试solr了,要注意服务器端Solr.war包的代码与eclipse的Solr代码一致。
二.Eclipse 的Solr环境搭建
2.1 Solr的编译
进入solr的目录,运行ant:
1 192:solr-4.8.0 rcf$ ant 2 Buildfile: /Users/rcf/workspace/java/solr/solr-4.8.0/build.xml 3 4 -projecthelp: 5 [-] Buildfile: /Users/rcf/workspace/java/solr/solr-4.8.0/build.xml 6 7 Main targets: 8 9 check-svn-working-copy Checks the status of the SVN working copy10 clean Clean Lucene and Solr build dirs11 clean-eclipse Removes all Eclipse configuration files12 clean-idea Removes all IntelliJ IDEA configuration files13 clean-jars Remove all JAR files from lib folders in the checkout14 clean-maven-build Clean up Maven POMs in working copy15 clean-netbeans Removes all Netbeans configuration files16 compile Compile Lucene and Solr17 compile-test Compile Lucene and Solr tests and test-frameworks18 documentation Generate Lucene and Solr Documentation19 documentation-lint Validates the generated documentation (HTML errors, broken links,...)20 eclipse Setup Eclipse configuration21 generate-maven-artifacts Generate Maven Artifacts for Lucene and Solr22 get-maven-poms Copy Maven POMs from dev-tools/maven/ to maven-build/23 idea Setup IntelliJ IDEA configuration24 ivy-bootstrap Download and install Ivy in the users ant lib dir25 jar Build Lucene and Solr Jar files26 jar-checksums Recompute SHA1 checksums for all JAR files.27 jar-src Build Lucene and Solr Source Jar files28 netbeans Setup Netbeans configuration29 nightly-smoke Builds an unsigned release and smoke tests it30 pitest Run PITest on both Lucene and Solr31 precommit Run basic checks before committing32 rat-sources Runs rat across all sources and tests33 regenerate Runs all code regenerators34 remove-maven-artifacts Removes all Lucene/Solr Maven artifacts from the local repository35 resolve Resolves all dependencies36 run-clover Runs all tests to measure coverage and generates report (pass "ANT_OPTS=-Xmx1536M" as environment)37 run-maven-build Runs the Maven build using automatically generated POMs38 test Test both Lucene and Solr39 test-help Test runner help40 test-with-heapdumps Runs tests with heap dumps on OOM enabled (if VM supports this)41 validate Validate dependencies, licenses, etc.42 validate-maven-dependencies Validates maven dependencies, licenses, etc.43 Default target: -projecthelp44 45 BUILD SUCCESSFUL46 Total time: 0 seconds
运行 ant eclipse就可以对solr源码进行编译成eclipse工程。在编译ant eclipse时候可能会失败,这是可以运行 ant ivy-bootstrap
2.2 将eclipse工程转换成WEB工程
将编译好的solr工程导入eclipse,后右键点击Properties,选中Project Facets,如图所示
选择OK后,就转换Solr的WEB工程了,这是有些xml文件会出现错误的红叉叉,不用管它。
2.3 solr.war包生成
进入solr/solr目录,运行ant dist,如下图所示
1 192:~ rcf$ cd /Users/rcf/workspace/java/solr/solr-4.8.0/solr 2 192:solr rcf$ ls 3 CHANGES.txt README.txt build.xml contrib docs package solrj 4 LICENSE.txt SYSTEM_REQUIREMENTS.txt cloud-dev core example scripts test-framework 5 NOTICE.txt build common-build.xml dist licenses site webapp 6 192:solr rcf$ ant dist 7 Buildfile: /Users/rcf/workspace/java/solr/solr-4.8.0/solr/build.xml 8 [echo] Building solr... 9 10 init-dist:11 12 dist-solrj:13 [echo] Building solr-solrj...14 15 check-lucene-core-uptodate:16 17 jar-lucene-core:
编译完成后会再dist目录下生产solr.war包
2.4 solr配置
1. 将solr.war copy到solr/WebContent目录下并进行解压。
2. 在WebRoot/META-INF目下创建context.xml 文件,配置solr/home。
1 <?xml version=‘1.0‘ encoding=‘utf-8‘?>2 <Context> 3 <Environment name="solr/home" type="java.lang.String" value=http://www.mamicode.com/"/Users/rcf/workspace/java/solr/Solr" override="true" />4 </Context>
3. 创建solr/home,在里面放入solr.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <solr> 3 <solrcloud> 4 <str name="host">${host:}</str> 5 <int name="hostPort">${jetty.port:8983}</int> 6 <str name="hostContext">${hostContext:solr}</str> 7 <int name="zkClientTimeout">${zkClientTimeout:30000}</int> 8 <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool> 9 </solrcloud>10 <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">11 <int name="socketTimeout">${socketTimeout:0}</int>12 <int name="connTimeout">${connTimeout:0}</int>13 </shardHandlerFactory>14 </solr>
4.这样就可以进行调试solr了。
三.Solr环境搭建
真实的solr环境搭建,跟eclipse的环境搭建类似,主要分为以下几步:
1. 对solr源码进行编译,ant dist生成solr.war
2. 下载tomcat并进行安装(tomcat的配置并不需要修改)
3. 将solr.war 复制到 ${TOMCAT_HOME}/wepapps目录下并将solr.war包解压成solr目录
4. 将solr/dist目录下的jar包全部拷贝到${TOMCAT_HOME}/wepapps/solr/lib目录下
5. 在${TOMCAT_HOME}/conf/Catalina/localhost/创建solr.xml,里面设置了solr/home
1 <Context docBase="/Users/rcf/workspace/java/tomcat/apache-tomcat-8.0.9/webapps/solr.war" debug="0" crossContext="true" >2 <Environment name="solr/home" type="java.lang.String" value=http://www.mamicode.com/"/Users/rcf/workspace/java/solr/Solr" override="true" />3 </Context>
6. 创建solr/home,也创建solr.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <solr> 3 <solrcloud> 4 <str name="host">${host:}</str> 5 <int name="hostPort">${jetty.port:8983}</int> 6 <str name="hostContext">${hostContext:solr}</str> 7 <int name="zkClientTimeout">${zkClientTimeout:30000}</int> 8 <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool> 9 </solrcloud>10 <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory">11 <int name="socketTimeout">${socketTimeout:0}</int>12 <int name="connTimeout">${connTimeout:0}</int>13 </shardHandlerFactory>14 </solr>
7. 在将solr源码包里的log4j.properties 拷贝到${TOMCAT_HOME}/lib目录下,并修改log文件路径
1 1 # Logging level 2 2 solr.log=/Users/rcf/workspace/java/tomcat/apache-tomcat-8.0.9/logs 3 3 log4j.rootLogger=INFO, file, CONSOLE 4 4 5 5 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 6 6 7 7 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 8 8 log4j.appender.CONSOLE.layout.ConversionPattern=%-4r [%t] %-5p %c %x \u2013 %m%n 9 9 10 10 #- size rotation with log cleanup.11 11 log4j.appender.file=org.apache.log4j.RollingFileAppender12 12 log4j.appender.file.MaxFileSize=4MB13 13 log4j.appender.file.MaxBackupIndex=914 14 15 15 #- File to log to and log format16 16 log4j.appender.file.File=${solr.log}/solr.log17 17 log4j.appender.file.layout=org.apache.log4j.PatternLayout18 18 log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n19 19 20 20 log4j.logger.org.apache.zookeeper=WARN21 21 log4j.logger.org.apache.hadoop=WARN22 22 23 23 # set to INFO to enable infostream log messages24 24 log4j.logger.org.apache.solr.update.LoggingInfoStream=OFF