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=7070
2 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 copy
10  clean                        Clean Lucene and Solr build dirs
11  clean-eclipse                Removes all Eclipse configuration files
12  clean-idea                   Removes all IntelliJ IDEA configuration files
13  clean-jars                   Remove all JAR files from lib folders in the checkout
14  clean-maven-build            Clean up Maven POMs in working copy
15  clean-netbeans               Removes all Netbeans configuration files
16  compile                      Compile Lucene and Solr
17  compile-test                 Compile Lucene and Solr tests and test-frameworks
18  documentation                Generate Lucene and Solr Documentation
19  documentation-lint           Validates the generated documentation (HTML errors, broken links,...)
20  eclipse                      Setup Eclipse configuration
21  generate-maven-artifacts     Generate Maven Artifacts for Lucene and Solr
22  get-maven-poms               Copy Maven POMs from dev-tools/maven/ to maven-build/
23  idea                         Setup IntelliJ IDEA configuration
24  ivy-bootstrap                Download and install Ivy in the users ant lib dir
25  jar                          Build Lucene and Solr Jar files
26  jar-checksums                Recompute SHA1 checksums for all JAR files.
27  jar-src                      Build Lucene and Solr Source Jar files
28  netbeans                     Setup Netbeans configuration
29  nightly-smoke                Builds an unsigned release and smoke tests it
30  pitest                       Run PITest on both Lucene and Solr
31  precommit                    Run basic checks before committing
32  rat-sources                  Runs rat across all sources and tests
33  regenerate                   Runs all code regenerators
34  remove-maven-artifacts       Removes all Lucene/Solr Maven artifacts from the local repository
35  resolve                      Resolves all dependencies
36  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 POMs
38  test                         Test both Lucene and Solr
39  test-help                    Test runner help
40  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: -projecthelp
44 
45 BUILD SUCCESSFUL
46 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="/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="/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.RollingFileAppender
12  12 log4j.appender.file.MaxFileSize=4MB
13  13 log4j.appender.file.MaxBackupIndex=9
14  14 
15  15 #- File to log to and log format
16  16 log4j.appender.file.File=${solr.log}/solr.log
17  17 log4j.appender.file.layout=org.apache.log4j.PatternLayout
18  18 log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS}; %C; %m\n
19  19 
20  20 log4j.logger.org.apache.zookeeper=WARN
21  21 log4j.logger.org.apache.hadoop=WARN
22  22 
23  23 # set to INFO to enable infostream log messages
24  24 log4j.logger.org.apache.solr.update.LoggingInfoStream=OFF

 

Solr4.8.0源码分析(4)之Eclipse Solr调试环境搭建,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。