最近公司项目要使用openfire,并对源码做一些修改,使用的openfire版本为官网目前最新版本4.2.3,网上资料较少,踩了很多坑,特此记录。
1.下载源码
http://www.igniterealtime.org/downloads/source.jsp
2.使用idea导入源码
File-New-Project from Existing Sources 导入解压后的源码
一路next
导入后的目录结构如下
设置Project SDK
打开File-Project Structure(本人使用的jdk1.8)
3.使用ant编译源码
a)打开右侧ant build菜单,点击+号,选择openfire-src-build下的build.xml文件
b)点击ant build菜单蓝色按钮(第四个)过滤
c)选择openfire后点击run按钮
4.配置运行参数
a)选择application
b)设置一些启动参数如图所示
c)启动(注意:此步会报一些错,下面一一解决)
Q:Error:java: 无效的源发行版: 1.9
A:此处选择8
Q:Error:(571, 21) java: 无法访问org.apache.tools.ant.Task
找不到org.apache.tools.ant.Task的类文件
A:缺少ant包
1.将idea路径下或者自己下载的ant.jar复制到openfire_src>build->ib>ant目录和openfire_src>build->ib>merge目录下
2.打开project structure,选择libraries下的ant和merge,将刚才的ant.jar添加进去
3.选择project structure-modules-tools模块,加入ant依赖
Q:启动成功,打开控制台页面报
HTTP ERROR 404
Problem accessing /login.jsp. Reason:
/login.jsp
Powered by Jetty://
A:在web>WEB-INF>web.xml中添加
<jsp-config>
<taglib>
<taglib-uri>admin</taglib-uri>
<taglib-location>/WEB-INF/admin.tld</taglib-location>
</taglib>
</jsp-config>
然后使用ant重新编译后启动
Q:再次启动后报500错误
HTTP ERROR 500
Problem accessing /setup/index.jsp. Reason:
Server Error
Caused by:
java.lang.NullPointerExceptionat org.jivesoftware.admin.AdminConsole.getAppName(AdminConsole.java:105)at org.jivesoftware.openfire.admin.decorators.setup_jsp._jspService(setup_jsp.java:192)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595)at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)at org.eclipse.jetty.server.Dispatcher.include(Dispatcher.java:115)at com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:156)at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:59)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)at org.jivesoftware.util.LocaleFilter.doFilter(LocaleFilter.java:73)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)at org.jivesoftware.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:49)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)at org.jivesoftware.admin.PluginFilter.doFilter(PluginFilter.java:226)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)at org.jivesoftware.admin.AuthCheckFilter.doFilter(AuthCheckFilter.java:215)at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)at org.eclipse.jetty.server.Server.handle(Server.java:499)at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)at java.lang.Thread.run(Thread.java:748)
A:缺少配置文件
1.将D:\IntelliJ IDEA 2017.3.3\workspace\openfire_src\src\resources\jar下的admin-sidebar.xml复制到D:\IntelliJ IDEA 2017.3.3\workspace\openfire_src\out\production\openfire_src
2.将D:\IntelliJ IDEA 2017.3.3\workspace\openfire_src\src\i18n下的所有文件复制到D:\IntelliJ IDEA 2017.3.3\workspace\openfire_src\out\production\openfire_src
成功进入控制台!!!