[置顶] import openfire4.0.2 source code in eclipse

【0】README
1)本文旨在给出 导入 openfire4.0.2 源码到 eclipse的具体 steps;
2)小生我导入该version 的 openfire 用了近2 天时间, 比较心酸,究其原因是 源码 引入的 jar 包不够全面,或引入路径错误,下面我会给出解决方法;
3)本文参考了如下post(不过按照他们的steps , 我一直没有导入成功):http://blog.csdn.net/lovexieyuan520/article/details/37743433  + https://308681282.gitbooks.io/openfire/content/di_si_zhang_openfire_yuan_ma_dao_ru_yi_ji_kai_fa.html
4)要知道, 原作者的 eclipse 项目 对jar 包导入的不够全面,但是它们都全部存在项目中,只不过没有全部添加到 项目的 build path 中;所以有些 post(包括上述两篇 post)提出要 down 相应 jar 并添加到 该项目中,这样做是不行的,因为 jar 包的 版本不匹配(至少我没有执行正确),而且源码中并不是缺少jar 包,而是jar包的导入路径错误而已;
5)jdk 要求:jdk1.7 以上(包括1.7, 项目根目录/build/build.xml 中有声明)

【1】import steps
step1)download source code from http://www.igniterealtime.org/downloads/source.jsp(this is our target link) , download installation release from http://www.igniterealtime.org/downloads/, also you can download source code from github via https://github.com/igniterealtime, and also you can checkout the openfire source code history releases from https://github.com/igniterealtime/Openfire/releases

step2)将该 source code zip 文件解压到某个文件夹下,如 eclipse_one 文件夹下;拷贝 eclipse_one\openfire_src_4_0_2\openfire_src\build\eclipse 中的所有文件到 eclipse_one\openfire_src_4_0_2\openfire_src 目录下,重命名它们的文件名,加上前缀 . 即可(这需要在win 命令行 下通过 rename 完成)(注意,下载下来的 openfire 源码没有 target 和 work 两个文件夹,这两个文件夹是ant 编译后生成的,这在后面会讲到)
[置顶] import openfire4.0.2 source code in eclipse_第1张图片
[置顶] import openfire4.0.2 source code in eclipse_第2张图片

Attention)本文 README 已经说到了, github作者源码中的 jar 包 有些 导入的不够全面,这些jar 的导入声明 在 .classpath 文件中;当我们在 eclipse中 添加 jar 文件到 build path 的时候,实际上是在修改这个 .classpath 文件中的 jar 包声明;(由于其jar 导入的不够全面,本文会在下面给出 解决方法)

step3) 然后打开Eclipse,选择 File –> Import… –> Existing Projects into Workspace, copy D:\classical_books\asiainfo\eclipse_one\openfire_src_4_0_2\openfire_src 到 select root directory(当然,这里我之前导入过,所以不能再次导入,只是为了说明这个 case, 截图而已)
[置顶] import openfire4.0.2 source code in eclipse_第3张图片

step4) 导入后,你会发现,项目会出现 红色的感叹号,这说明,我们的 build path 中的jar 导入路径有问题;光标到项目->右键->build path -> Libraries (我这里的项目没有红色感叹号,是因为我理清了 jar 包的导入路径,下面会给出 导入全部 jar的正确方式);


【2】proble+solutions(对的,这里有两种解决方法)
1)problem:正如README 所说,github raw source code 中的jar导入路径不够全面(即 .classpath 文件中声明导入jar 的导入路径有问题,或其根本就不存在);
2)solutions
2.1)solution1:你可以直接下载我的 .classpath 并覆盖 你项目下的 .classpath,重启 eclipse 即可(因为,我已经理清了 jar 包的导入路径,所以你只需要将其 正确的 导入路径描述(.classpaht) 覆盖原来的  .classpath 即可);(down site https://github.com/pacosonTang/core-java-volume/blob/master/openfire_supplement/.classpath
2.2)solution2:手动理清 jar包的导入路径;首先,需要在 java build path 中 将 缺少的 jar 全部 移除,然后添加 项目中的 没有导入的jar包 到 build path;


Supplement) 通过分析 .classpath 文件,你会发现, openfire 中的jar 存在于 build/lib 及其子文件夹下面 和 存在于 各个plugins 文件夹下面;其代码(.classpath)声明如下:(这就是为什么我们需要添加 原作者遗漏的本应该 导入jar 的原因)
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src/java"/>
 <classpathentry kind="src" path="src/i18n"/>
 <classpathentry kind="src" path="build/lib/dist"/>
 <classpathentry kind="src" path="src/resources/jar"/>
 <classpathentry kind="src" output="work/plugins-dev/broadcast/target/classes" path="src/plugins/broadcast/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/clientControl/target/classes" path="src/plugins/clientControl/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/contentFilter/target/classes" path="src/plugins/contentFilter/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/dbaccess/target/classes" path="src/plugins/dbaccess/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/emailListener/target/classes" path="src/plugins/emailListener/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/fastpath/target/classes" path="src/plugins/fastpath/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/gojara/target/classes" path="src/plugins/gojara/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/jingleNodes/target/classes" path="src/plugins/jingleNodes/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/justmarried/target/classes" path="src/plugins/justmarried/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/kraken/target/classes" path="src/plugins/kraken/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/loadStats/target/classes" path="src/plugins/loadStats/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/monitoring/target/classes" path="src/plugins/monitoring/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/motd/target/classes" path="src/plugins/motd/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/nodejs/target/classes" path="src/plugins/nodejs/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/packetFilter/target/classes" path="src/plugins/packetFilter/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/presence/target/classes" path="src/plugins/presence/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/registration/target/classes" path="src/plugins/registration/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/search/target/classes" path="src/plugins/search/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/stunserver/target/classes" path="src/plugins/stunserver/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/subscription/target/classes" path="src/plugins/subscription/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/userCreation/target/classes" path="src/plugins/userCreation/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/userImportExport/target/classes" path="src/plugins/userImportExport/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/userservice/target/classes" path="src/plugins/userservice/src/java"/>
 <classpathentry kind="src" output="work/plugins-dev/xmldebugger/target/classes" path="src/plugins/xmldebugger/src/java"/>
 <classpathentry kind="src" path="src/test/java"/>
 <classpathentry kind="src" path="src/test/throttletest/src"/>
 <classpathentry kind="lib" path="build/lib/ant/ant-contrib.jar"/>
 <classpathentry kind="lib" path="build/lib/cglib-nodep.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/hsqldb.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/jtds.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/mail.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/mysql.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/postgres.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/slf4j-log4j12.jar"/>
 <classpathentry kind="lib" path="build/lib/i4jruntime.jar"/>
 <classpathentry kind="lib" path="build/lib/jmock-junit4.jar"/>
 <classpathentry kind="lib" path="build/lib/jmock-legacy.jar"/>
 <classpathentry kind="lib" path="build/lib/jmock.jar"/>
 <classpathentry kind="lib" path="build/lib/junit.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/commons-codec.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/commons-httpclient.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/commons-lang.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/commons-logging.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/concurrentlinkedhashmap-lru-1.0_jdk5.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/dbutil.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/dom4j.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jaxen.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jdom.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-continuation.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-http.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-io.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-security.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-server.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-servlet.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-util.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-webapp.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-xml.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jmdns.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jzlib.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/libidn.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/log4j.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/mina-core.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/mina-filter-compression.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/proxool.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/rome-fetcher.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/rome.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/shaj.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/sitemesh.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/slf4j-api.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/standard.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/stringprep.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/tinder.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/xpp3.jar"/>
 <classpathentry kind="lib" path="build/lib/objenesis.jar"/>
 <classpathentry kind="lib" path="build/lib/src/commons-lang-sources.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/xmltask.jar"/>
 <classpathentry kind="lib" path="src/plugins/clientControl/lib/commons-fileupload-1.0.jar"/>
 <classpathentry kind="lib" path="src/plugins/fastpath/lib/commons-fileupload-1.0.jar"/>
 <classpathentry kind="lib" path="src/plugins/fastpath/lib/lucene.jar"/>
 <classpathentry kind="lib" path="src/plugins/fastpath/lib/xstream.jar"/>
 <classpathentry kind="lib" path="src/plugins/gojara/lib/json.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/concurrent.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/dwr.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/httpclient.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/httpcore.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jainsipapi.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jainsipri.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jakarta-regexp.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jcip-annotations.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jggapi.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jml.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/joscar-common.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/joscar-protocol.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jqql.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/jsocks.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/json.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/martyr.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/msim.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/openymsg.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/smack.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/smackx.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/stcomm.jar"/>
 <classpathentry kind="lib" path="src/plugins/kraken/lib/xmlrpc.jar"/>
 <classpathentry kind="lib" path="src/plugins/jingleNodes/lib/jnsapi.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/dwr.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/itext.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/jcommon.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/jfreechart.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/jrobin.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/lucene.jar"/>
 <classpathentry kind="lib" path="src/plugins/monitoring/lib/picocontainer.jar"/>
 <classpathentry kind="lib" path="src/plugins/registration/lib/recaptcha4j.jar"/>
 <classpathentry kind="lib" path="src/plugins/sip/lib/JainSipApi1.1.jar"/>
 <classpathentry kind="lib" path="src/plugins/sip/lib/nist-sip-1.2.jar"/>
 <classpathentry kind="lib" path="src/plugins/userImportExport/lib/commons-fileupload-1.0.jar"/>
 <classpathentry kind="lib" path="src/plugins/userImportExport/lib/isorelax.jar"/>
 <classpathentry kind="lib" path="src/plugins/userImportExport/lib/msv.jar"/>
 <classpathentry kind="lib" path="src/plugins/userImportExport/lib/relaxngDatatype.jar"/>
 <classpathentry kind="lib" path="src/plugins/userImportExport/lib/xsdlib.jar"/>
 <classpathentry kind="lib" path="src/test/throttletest/build/lib/smack.jar"/>
 <classpathentry kind="lib" path="src/test/throttletest/build/lib/smackx.jar"/>
 <classpathentry kind="lib" path="src/web/WEB-INF/lib/commons-fileupload.jar"/>
 <classpathentry kind="lib" path="src/web/WEB-INF/lib/commons-io.jar"/>
 <classpathentry kind="lib" path="src/web/WEB-INF/lib/dwr.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/servlet-api.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/ant-junit.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/ant-junit4.jar"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
 <classpathentry kind="lib" path="src/plugins/stunserver/lib/jstun-0.6.1.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-jmx.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/mina-integration-jmx.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/bcpg-jdk15on.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/bcpkix-jdk15on.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/bcprov-jdk15on.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-servlets.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/spdy-client.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/spdy-core.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/spdy-http-common.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/spdy-http-server.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/spdy-server.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/javax-websocket-client-impl.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/javax-websocket-server-impl.jar"/>
 <classpathentry kind="lib" path="src/plugins/callbackOnOffline/lib/javax.ws.rs-api-2.0.1.jar"/>
 <classpathentry kind="lib" path="src/plugins/userservice/lib/jersey-bundle-1.18.jar"/>
 <classpathentry kind="lib" path="build/lib/hamcrest-core.jar"/>
 <classpathentry kind="lib" path="build/lib/jaxb-api.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/jugbbant-1.7.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/slf4j-simple.jar"/>
 <classpathentry kind="lib" path="build/lib/ant/xalan.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/javax.websocket-api.jar"/>
 <classpathentry kind="lib" path="build/lib/dist/npn-boot.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/javassist.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/javax.websocket-api.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-plus.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/jetty-schemas.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/mina-integration-beans.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/mina-integration-ognl.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/ognl.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.apache.taglibs.taglibs-standard-impl.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.apache.taglibs.taglibs-standard-spec.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.eclipse.jetty.apache-jsp.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.eclipse.jetty.orbit.org.eclipse.jdt.core.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.mortbay.jasper.apache-el.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/org.mortbay.jasper.apache-jsp.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/websocket-api.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/websocket-client.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/websocket-common.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/websocket-server.jar"/>
 <classpathentry kind="lib" path="build/lib/merge/websocket-servlet.jar"/>
 <classpathentry kind="lib" path="build/lib/src/ant-jive-edition-sources.jar"/>
 <classpathentry kind="lib" path="build/lib/src/slf4j-api-sources.jar"/>
 <classpathentry kind="lib" path="build/lib/src/slf4j-log4j12-sources.jar"/>
 <classpathentry kind="output" path="work/classes"/>
</classpath>

【3】利用 ant 编译openfire 源码
step5) ant 编译项目: build/build.xml ->run as -> ant build -> 执行ant编译源码 ; 编程成功后,会在项目 根目录下生成两个新的文件夹:target 和 work 。
[置顶] import openfire4.0.2 source code in eclipse_第4张图片

【4】运行 openfire 项目
step6)Build Path配置中把  /openfirec/src/i18n 、/openfire/src/resources/jar 、/openfire/build/lib/dist 文件夹添加到 Source 中


step7)配置启动参数: run ->run configurations 

把默认name:New_configuration 修改成:ServerStarter。

选中Main选项卡,点击Browse按钮选择 openfire_src 项目;单击Search 按钮输入:ServerStarter 自动过滤后选择:ServerStarter – org.jivesoftware.openfire.starter:

[置顶] import openfire4.0.2 source code in eclipse_第5张图片

选中Arguments选项卡,在VM arguments中填入:

-DopenfireHome=${workspace_loc:openfire}/target/openfire

注意:项目路径 ${workspace_loc:openfire}

[置顶] import openfire4.0.2 source code in eclipse_第6张图片


选中Common选项卡,将Debug和Run打钩(方便之后快速启动),然后点击apply,再点击run:



【5】运行结果
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/classical_books/asiainfo/eclipse_one/openfire_src_4_0_2/openfire_src/build/lib/dist/slf4j-log4j12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/classical_books/asiainfo/eclipse_one/openfire_src_4_0_2/openfire_src/build/lib/ant/slf4j-simple.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Openfire 4.0.2 [Jul 10, 2016 2:00:17 PM]
Admin console listening at http://lenovo-pc:9090 //(表明管理器控制台 正在监听9090 端口)
最后:  接着输入  http://localhost:9090  , 进入控制台进行 openfire 的相关配置, (就到这里了,接下来的steps 都比较简单了)


你可能感兴趣的:([置顶] import openfire4.0.2 source code in eclipse)