openfire+spark二次开发

前断时间因为项目需要用到openfire,用了一个月时间研究以及进行二次开发,也是累的够呛,现在做一些总结希望帮助需要的人

  1. openfire插件的开发

首先下载openfire源码导入myeclipse具体方法参考博文

http://blog.csdn.net/daigua245/article/details/7918243

在该目录下包含了openfire官方提供的所有插件 /openfire/src/plugins,进行插件开发只需在该目录下建立自己的插件具体目录结构可以模仿fastpath插件(直接在项目下进行插件开发好处就是比较好进行代码调试),具体格式如图

 

具体插件插件开发细节可以参考博文http://blog.csdn.net/ibm_hoojo/article/details/8645369

为了方便插件打包可使用ant文件,和上面博文介绍的ant文件略有不同,主要因为开发路径不一样了

build_test.xml(打包的插件目录结构必须和fastpath的一样)

<span style="font-size:14px;"><project name="Webapp Precompilation" default="openfire-plugins" basedir=".">
    <property file="build.properties" />
    
    <!-- java servlet相关文件编译jar存放位置 -->
    <property name="java.jar.dir" value="${webapp.path}/java-dist"/>
    <!-- jsp servlet编译后jar存放位置 -->
    <property name="jsp.jar.dir" value="${webapp.path}/jsp-dist/lib"/>
        
    <!-- 定义java servlet和jsp servlet的jar包名称 -->
    <property name="java.jar" value="${java.jar.dir}/plugin-${plugin.name}.jar"/>
    <property name="jsp.jar" value="${jsp.jar.dir}/plugin-${plugin.name}-jsp.jar"/>
    
    <!-- jsp servlet配置到web.xml中 -->
    <property name="plugin.web.xml" value="${webapp.path}/jsp-dist/web.xml"/>
        
    <!-- 编译jsp 并生成相关jar、xml文件 -->
    <target name="jspc">
        
        <taskdef classname="org.apache.jasper.JspC" name="jasper2">
            <classpath id="jspc.classpath">
                <pathelement location="${java.home}/../lib/tools.jar" />
            	<fileset dir="${tomcat.home1}">
            	                    <include name="**/*.jar" />
            	                </fileset>
            	<fileset dir="../../lib">
            	                    <include name="**/*.jar" />
            	                </fileset>
            	<pathelement location="E:\java\Workspaces\MyEclipse9\openfire\bin" />
            </classpath>
        </taskdef>
                    
        <jasper2 javaEncoding="UTF-8" validateXml="false"
            uriroot="${plugin.path}/src/web"
            outputDir="${webapp.path}/jsp-dist/src"
            package="com.hoo.openfire.plugin.${plugin.name}" />
        
        <jasper2
            validateXml="false"
            uriroot="${plugin.path}/src/web"
            outputDir="${webapp.path}/jsp-dist/src"
            package="com.hoo.openfire.plugin.${plugin.name}"
            webXml="${plugin.web.xml}"/>
    </target>
    
    <!-- 编译jsp 并打jar包 -->
    <target name="compile">
 
        <mkdir dir="${webapp.path}/jsp-dist/classes" />
        <mkdir dir="${webapp.path}/jsp-dist/lib" />
        <mkdir dir="${webapp.path}/jsp-dist/src" />
        
        <javac destdir="${webapp.path}/jsp-dist/classes" optimize="off"
            encoding="UTF-8" debug="on" failοnerrοr="false" includeantruntime="true"
            srcdir="${webapp.path}/jsp-dist/src" excludes="**/*.smap">
            <!-- compilerarg value="-Xlint:unchecked"/
            <compilerarg value="-Xlint"/>-->
            <classpath>
                <pathelement location="${webapp.path}/jsp-dist/classes" />
                <fileset dir="${webapp.path}/jsp-dist/lib">
                    <include name="*.jar" />
                </fileset>
                <pathelement location="${tomcat.home1}/common/classes" />
                
                <fileset dir="${tomcat.home1}">
                    <include name="**/*.jar" />
                </fileset>
            	<fileset dir="../../lib">
                    <include name="**/*.jar" />
                </fileset>
                <pathelement location="../../bin" />
                <pathelement location="${webapp.path}/bin" />
                <fileset dir="${webapp.path}/lib">
                    <include name="**/*.jar" />
                </fileset>
            </classpath>
            <include name="**" />
            <exclude name="tags/**" />
        </javac>
        
        <jar jarfile="${jsp.jar}" basedir="${webapp.path}/jsp-dist/classes" />
    </target>
 
    <!-- 将java servlet打包成jar -->
    <target name="java-jar">
        <mkdir dir="${java.jar.dir}"/>
    	<mkdir dir="${java.jar.dir}/classes" />
        <javac destdir="${java.jar.dir}/classes" optimize="off"
            encoding="UTF-8" debug="on" failοnerrοr="false" includeantruntime="true"
            srcdir="${plugin.path}/src/java" excludes="**/*.smap">
           <classpath>
                <fileset dir="../../lib">
                    <include name="**/*.jar" />
                </fileset>
           		<fileset dir="../../lib">
                    <include name="**/*.jar" />
                </fileset>
           		<fileset dir="${plugin.path}/lib">
                    <include name="*.jar" />
                </fileset>
           		<fileset dir="${webapp.path}/lib">
           	        <include name="*.jar" />
           	    </fileset>
           		<fileset dir="../../build/lib">
                    <include name="**/*.jar" />
                </fileset>
                <pathelement location="../../bin" />
            </classpath>
            <include name="**" />
        </javac>
        <jar jarfile="${java.jar}">
            <fileset dir="${java.jar.dir}/classes" includes="**/*.class"/>
        </jar>    
    </target>    
 
    <!-- 生成可部署的插件包 -->
    <target name="plug-jar">
        <!-- 插件插件包相关lib、 web目录 -->
        <mkdir dir="${webapp.path}/${plugin.name}/lib"/>
        <mkdir dir="${webapp.path}/${plugin.name}/web/WEB-INF"/>
 
        <!-- 复制jsp servlet的jar和java servlet的相关jar包到插件包的lib目录下 -->
        <copy file="${java.jar}" todir="${webapp.path}/${plugin.name}/lib"/>
        <copy file="${jsp.jar}" todir="${webapp.path}/${plugin.name}/lib"/>
 
    	<copy todir="${webapp.path}/${plugin.name}/lib">
            <fileset dir="${plugin.path}/lib" includes="*.jar"/>
        </copy>
    	<copy todir="${webapp.path}/${plugin.name}/database">
            <fileset dir="${plugin.path}/src/database" includes="*.*"/>
        </copy>
    	        	
        <!-- 将相关的图片、帮助文档、修改日志等文件复制到插件目录下 -->
        <copy todir="${webapp.path}/${plugin.name}">
            <fileset dir="${plugin.path}" includes="*.*"/>
        </copy>
        <copy todir="${webapp.path}/${plugin.name}/web">
            <fileset dir="${plugin.path}/src/web">
                <include name="*"/>
                <include name="**/*.*"/>
                <exclude name="**/*.xml"/>
                <exclude name="**/*.jsp"/>
            </fileset>
        </copy>
        <!-- jsp servlet的web复制到插件目录下 -->
        <copy file="${plugin.web.xml}" todir="${webapp.path}/${plugin.name}/web/WEB-INF"/>
        <copy todir="${webapp.path}/${plugin.name}/web">
            <fileset dir="${plugin.path}/src/web" includes="**/*.xml"/>
        </copy>
        <!-- 将国际化相关资源文件复制到插件目录下 
        <copy file="${webapp.path}/bin/i18n" todir="${webapp.path}/${plugin.name}"/>
        -->
        <!-- 产生可部署插件包 -->
        <jar jarfile="${webapp.path}/${plugin.name}.jar">
            <fileset dir="${webapp.path}/${plugin.name}" includes="**/**"/>
        </jar>    
    </target>    
    
    <!-- 生成没有Web资源的可部署插件包 -->
    <target name="java-plug-jar">
        <!-- 插件插件包相关lib、 web目录 -->
        <mkdir dir="${webapp.path}/${plugin.name}/lib"/>
 
        <!-- 复制java servlet的相关jar包到插件包的lib目录下 -->
        <copy file="${java.jar}" todir="${webapp.path}/${plugin.name}/lib"/>
 
        <!-- 将相关的图片、帮助文档、修改日志等文件复制到插件目录下 -->
        <copy todir="${webapp.path}/${plugin.name}">
            <fileset dir="${plugin.path}" includes="*.*"/>
        </copy>
        
        <!-- 产生可部署插件包 -->
        <jar jarfile="${webapp.path}/${plugin.name}.jar">
            <fileset dir="${webapp.path}/${plugin.name}" includes="**/**"/>
        </jar>    
    </target>
                    
    <!-- 清理生成的文件 -->
    <target name="clean">
        <delete file="${webapp.path}/${plugin.name}.jar"/>
        <delete dir="${webapp.path}/${plugin.name}"/>
        <delete dir="${webapp.path}/jsp-dist"/>
        <delete dir="${webapp.path}/java-dist"/>
    </target>
    
    <target name="all" depends="clean,jspc,compile"/>
 
    <target name="openfire-plugin" depends="jspc,java-jar"/>
 
    <target name="openfire-plugins" depends="all,java-jar,plug-jar"/>
    
    <target name="openfire-plugin-java" depends="clean,java-jar,java-plug-jar"/>
</project></span>
build.properties
<span style="font-size:14px;">tomcat.home1=E\:\\tomcat-5.0.28
webapp.path=E\:\\java\\Workspaces\\openfire\\piugin-build
plugin.name=chatlogs
plugin.path=E\:\\java\\Workspaces\\openfire\\src\\plugins\\chatlogs</span>

将这两个文件放在/openfire/src/plugins目录下

在项目根目录下建立文件夹/piugin-build

运行ant即可在piugin-build下生成相应的jar包

将jar拷贝到/openfire/target/openfire/plugins目录下即可

集成系统用户
通过配置/openfire/src/conf/openfire.xml进行集成,也可手动修改数据库表ofproperty
<?xml version="1.0" encoding="UTF-8"?>
<!--
    This file stores bootstrap properties needed by Openfire.
    Property names must be in the format: "prop.name.is.blah=value"
    That will be stored as:
        <prop>
            <name>
                <is>
                    <blah>value</blah>
                </is>
            </name>
        </prop>

    Most properties are stored in the Openfire database. A
    property viewer and editor is included in the admin console.
    <xmpp> 
    	<domain>192.168.152.1</domain> 
  	</xmpp>
-->
<!-- root element, all properties must be under this element -->
<jive>
    <adminConsole>
        <!-- Disable either port by setting the value to -1 -->
        <port>9090</port>
        <securePort>9091</securePort>
    </adminConsole>
	<admin> 
    	<authorizedUsernames>admin</authorizedUsernames> 
  	</admin>  
    <locale>zh_CN</locale>

    <!-- Network settings. By default, Openfire will bind to all network interfaces.
      Alternatively, you can specify a specific network interfaces that the server
      will listen on. For example, 127.0.0.1. This setting is generally only useful
       on multi-homed servers. -->
    <!--
    <network>
        <interface></interface>
    </network>
    -->
    <provider> 
	    <auth> 
	      <className>org.jivesoftware.openfire.auth.JDBCAuthProvider</className> 
	    </auth>  
	    <user> 
	      <className>org.jivesoftware.openfire.user.JDBCUserProvider</className> 
	    </user>  
	    <group> 
	      <className>org.jivesoftware.openfire.group.JDBCGroupProvider</className> 
	    </group> 
  	</provider>  
  	<jdbcProvider>
    	<driver>oracle.jdbc.driver.OracleDriver</driver>  
    	<connectionString>jdbc:oracle:thin:test/test@192.168.0.1:1521:orcl</connectionString> 
  	</jdbcProvider>  
  	<jdbcAuthProvider> 
    	<passwordSQL>SELECT password FROM view_all_users WHERE id=?</passwordSQL>  
    	<findIdByUsername>SELECT id FROM view_all_users WHERE username=?</findIdByUsername>  
    	<passwordType>md5</passwordType> 
  	</jdbcAuthProvider>
  	<jdbcUserProvider> 
	    <loadUserSQL>SELECT username ,'none@openfire.com' as email FROM view_all_users where id=? </loadUserSQL>  
	    <userCountSQL>SELECT COUNT(*) FROM view_all_users</userCountSQL>  
	    <allUsersSQL>SELECT id FROM view_all_users</allUsersSQL>
	    <searchSQL>SELECT id FROM view_all_users WHERE</searchSQL>  
	    <usernameField>id</usernameField>  
	    <nameField>username</nameField>  
	    <emailField>email</emailField> 
  	</jdbcUserProvider>
  	<jdbcGroupProvider>
  		<descriptionSQL>SELECT name FROM OPENFIRE_GROUP_CONFIG where sn=?</descriptionSQL>
  		<allGroupsSQL>SELECT sn FROM OPENFIRE_GROUP_CONFIG</allGroupsSQL>
  		<groupCountSQL>SELECT count(sn) FROM OPENFIRE_GROUP_CONFIG</groupCountSQL>
  		<loadAdminsSQL>SELECT admin FROM OPENFIRE_GROUP_CONFIG where sn=?</loadAdminsSQL>
  		<loadMembersSQL>SELECT id FROM view_all_users where flag=?</loadMembersSQL>
  		<userGroupsSQL>SELECT flag FROM view_all_users where id=?</userGroupsSQL>
  	</jdbcGroupProvider>
  	<database> 
    <defaultProvider> 
      <driver>com.mysql.jdbc.Driver</driver>  
      <serverURL>jdbc:mysql://localhost:3306/openfire</serverURL>  
      <username>root</username>  
      <password>root</password>  
      <testSQL>select 1</testSQL>  
      <testBeforeUse>true</testBeforeUse>  
      <testAfterUse>true</testAfterUse>  
      <minConnections>5</minConnections>  
      <maxConnections>15</maxConnections>  
      <connectionTimeout>1.0</connectionTimeout> 
    </defaultProvider> 
  </database>  
  	<setup>true</setup>  
	  <log> 
	    <debug> 
	      <enabled>true</enabled> 
	    </debug> 
	  </log> 
</jive>


spark二次开发
下载spark源码后导入eclipse中
找到/spark/src/java/org/jivesoftware/launcher/Startup.java进行项目启动,启动前需要配置相关参数
配置argument
-Djava.library.path=build/lib/dist/windows
-Dplugin=src/plugins/fastpath/plugin.xml
-Ddebug.mode=true
-Dsmack.debugEnabled=true
配置classpath


 相关文件说明
/spark/src/java/org/jivesoftware/resource/default.properties spark相关配置如禁用或启用一些功能,软件名等等
/spark/build/build.xml 用于spark打包文件的生成
/spark/src/commercial 保存打包的插件 spark进行build时会加入该文件夹下的插件
生成exe文件需要使用install4j来完成,具体方法见http://blog.sina.com.cn/s/blog_6c85d5c10100n1mn.html

web客户端开发

注意:
1、如果有使用咨询系统也就是fastpath要注意,他是不支持集群的
2、openfire的domain最好设置成ip
3、fastpath的webchat客户端插件如果使用用户名密码登入咨询有bug 连接成功后没过多久就会断开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值