tigase相关参考资料--linux+tigase+postgresql 二次开发环境搭建【草稿】

参考资料

搭建Tigase进行二次开发

idea搭建tigase源码环境

tigase服务端二次开发官方文档

在这里插入图片描述

配置【草稿-试错】

获取源代码

下载源代码到特定目录:

git clone -b stable https://git.tigase.tech/tigase-server.git ~/git-projects/tigase-server

在这里插入图片描述

在这里插入图片描述

下载完成。

数据库配置

请先看下图

在这里插入图片描述

誒,可以用db-create-mysql.sh这个脚本的。。
嗯,我们直接来看看源代码吧:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

嗯,感觉都可以差不多知道数据库结构了。

开始:
打开目录:

cd /home/too-white/git-projects/tigase-server/
##./scripts/db-create-postgresql.sh tigase_username tigase_password database_name database_host
./scripts/db-create-postgresql.sh tigase_db_mgr 123456 tigase_db localhost

在这里插入图片描述

咦,找不到主要类。。。嗯,经典错误。

在这里插入图片描述

jar和scripts是平级的,然而,sh脚本里面这样调用:
在这里插入图片描述

初步怀疑是路径问题,改路径为:

在这里插入图片描述
保存,然后执行:

在这里插入图片描述

还是有问题。。。
算了,暂时不管,回滚到之前的状态,现在来直接建立项目。

项目建立

用idea新建一个gradle以及java的新项目:

在这里插入图片描述

然后,将源代码除了git相关的都复制一份到项目下面:

在这里插入图片描述

然后,重启一下idea:
在这里插入图片描述

好了,注意一下,idea会提示你要不要导入maven模块—当然不要了,用的构建工具是gradle,那么我们现在来转换一下,将maven的依赖都导入到gradle,然后删除maven文件。
在这里插入图片描述

变更为:
在这里插入图片描述

当然,我们还要设置一下国内的仓库:

plugins {
    id 'groovy'
    id 'java'
}

group 'net.w2p'
version '1.0-SNAPSHOT'

/***所有项目共通***/
allprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'groovy'

    idea {
        module {
            inheritOutputDirs = true
        }
    }
    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
    }
    tasks.withType(GroovyCompile) {
        groovyOptions.encoding = "MacRoman"
    }
    repositories {
        maven{
            //更换为阿里的仓库
            url  'http://maven.aliyun.com/nexus/content/groups/public'
        }
        //有些jar包在中央仓库是没有的,需要手动添加上去
//        flatDir {  dirs 'local_jars' }
//        mavenCentral()
    }
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    compile 'tigase:tigase-utils:3.5.1'
    compile 'tigase:tigase-xmltools:3.5.0'
    compileOnly 'org.apache.felix:org.osgi.core:1.4.0'
    compileOnly 'org.slf4j:jul-to-slf4j:${slf4j.version}'
    //数据库驱动
    compile 'mysql:mysql-connector-java:8.0.13'
    compile 'org.postgresql:postgresql:42.2.2'
    
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

然后我们要开始尝试做些事情了,譬如,进行之前不成功的数据库初始化。

在这里插入图片描述

看看DBSchemaLoader,发现有问题:
在这里插入图片描述

源代码里面竟然没有这个东西,不过找到文章:
在这里插入图片描述

好,导入 tigase-utils

在这里插入图片描述

git clone https://git.tigase.tech/tigase-utils.git  ~/git-projects/tigase-utils

在这里插入图片描述

查看一下里面的结构,看看有没有源代码bareJID文件:
在这里插入图片描述

有了,嗯,估计就是要有这些依赖。

导入tigase-xmltools:
在这里插入图片描述

然后:

git clone https://git.tigase.tech/tigase-xmltools.git  ~/git-projects/tigase-xmltools

在这里插入图片描述

好了,然后我们将utils以及xmltools的src里面的内容都复制到项目中,重启idea,发现还有有错:
在这里插入图片描述

对了,BareJID这个是跟之前的引用不一样的。。。额????能够出这种问题吗?
感觉这样改下去的话是无底洞。

好了,继续改下去,全文替换,项目里面的barejid引用都替换一下。

在这里插入图片描述
barejid看来是核心类来的。都替换。

尝试运行某个类,进行编译。譬如:
这个,因为要初始化数据库。
在这里插入图片描述

当然会有错了:
在这里插入图片描述

JID已经在tigase.xmpp.jid包下面,而TigaseStringrepException路径也部队。。嗯都替换:
在这里插入图片描述

在这里插入图片描述

好了,继续这种步骤一路下去:
在这里插入图片描述

下面的替换等操作就省略了:
我想说,稳定版的源代码绝对落后于主要版本,类的路径都变了也是醉了。

后续

放弃stable版本源代码的编译修改工作,因为我发现,从git上面拿到的最新版本跟stable版本代码明显不一样:

同一个文件:

最新版的loggertask
在这里插入图片描述

stable版本的loggertask
在这里插入图片描述

连调用的代码,调用的api类都变了。。。

所以,网上的这篇文章:
搭建Tigase进行二次开发

是没办法采信了。要update内容了。

最新版本的tigase+tigase-utils+tigase-xmltools源代码项目合并及编译

声明
本文编译时候,tigase server的版本是7.1.4

获取必要源代码

tigase的服务端包括三个项目,tigase-server,tigase-utils,tigase-xmltools,针对当前版本,7.1.4 而言,先用git克隆到本地:

git clone https://git.tigase.tech/tigase-server.git ~/git-projects/tigase-server-beta

在这里插入图片描述

导入 tigase-utils

在这里插入图片描述

git clone https://git.tigase.tech/tigase-utils.git  ~/git-projects/tigase-utils

在这里插入图片描述

导入tigase-xmltools:
在这里插入图片描述

然后:

git clone https://git.tigase.tech/tigase-xmltools.git  ~/git-projects/tigase-xmltools

在这里插入图片描述

新建idea项目

新建项目的时候选gradle以及groovy,其他以后再说:

在这里插入图片描述

一步一步下去:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

复制合并源代码

将tigase-server-beta下面的server文件夹的内容都复制到TigaseServer项目下面,
将tigase-utils的src以及tigase-xmltools下面的src都复制合并到TigaseServer下面,
在这里插入图片描述

正常来说,合并过程是不会有覆盖文件提示的—因为他们都是同一个项目的。。。不会文件冲突
然后重启idea:
在这里插入图片描述

有maven项目导入的提示,别管他,我们用的是gradle。

在这里插入图片描述

配置依赖

tigase-server项目的pom.xml文件肯定有依赖,我们现在来解决一下,将依赖都放到build.gradle下面。

在这里插入图片描述

咦,pom里面都已经写明了对 tigase-utils以及tigase-xmltools的依赖。。。额,我们刚才的下载源代码合并的操作估计是多此一举。不过算了,继续:

build.gradle内容:

plugins {
    id 'groovy'
    id 'java'
}

group 'net.w2p'
version '1.0-SNAPSHOT'

/***所有项目共通***/
allprojects {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    apply plugin: 'java'
    apply plugin: 'idea'
    apply plugin: 'groovy'

    idea {
        module {
            inheritOutputDirs = true
        }
    }
    tasks.withType(JavaCompile) {
        options.encoding = "UTF-8"
    }
    tasks.withType(GroovyCompile) {
        groovyOptions.encoding = "MacRoman"
    }
    repositories {
        maven{
            //更换为阿里的仓库
            url  'http://maven.aliyun.com/nexus/content/groups/public'
        }
        //有些jar包在中央仓库是没有的,需要手动添加上去
//        flatDir {  dirs 'local_jars' }
//        mavenCentral()
    }
}


dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.12'

    compileOnly 'org.apache.felix:org.osgi.core:1.4.0'

    compileOnly 'org.osgi:org.osgi.compendium:5.0.0'

    compileOnly 'org.slf4j:jul-to-slf4j:${slf4j.version}'

    compileOnly 'org.codehaus.groovy:groovy:2.5.2'

    compileOnly 'org.codehaus.groovy:groovy-json:2.5.2'

    compileOnly 'org.codehaus.groovy:groovy-jsr223:2.5.2'

    compileOnly 'org.codehaus.groovy:groovy-templates:2.5.2'

    compileOnly 'org.codehaus.groovy:groovy-xml:2.5.2'

    testCompile 'mysql:mysql-connector-java:5.1.40'

    testCompile 'net.sourceforge.jtds:jtds:1.2.8'

    testCompile 'org.postgresql:postgresql:9.4.1207'

    testCompile 'org.apache.derby:derby:10.12.1.1'
    
    
}

注意,修改build.gradle文件以后请重新加载依赖库。

然后找到:

DBSchemaLoader

以这个类为demo,进行编译。

在这里插入图片描述

编译执行结果:
在这里插入图片描述

#!/usr/bin/env groovy

嗯,这个是用来在linux下面直接作为shell运行的,idea,jvm不认可。。。

改了,然后:
在这里插入图片描述

我们看看slf4j的jar包:
在这里插入图片描述

这个导入不成功。。。嗯,
好了,改为:

在这里插入图片描述

<!-- https://mvnrepository.com/artifact/org.slf4j/jul-to-slf4j -->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jul-to-slf4j</artifactId>
    <version>1.7.25</version>
</dependency>

继续编译:
在这里插入图片描述

额。。完全找不到jidutils。。。实在没办法,注释掉再说:
在这里插入图片描述

然后就执行成功了,不过有提示,没按规则运行:

在这里插入图片描述

基本正常运行

数据库初始化

可以参考下以下兄弟的做法:
在这里插入图片描述

所以我们这样做:
在这里插入图片描述

然后添加参数:

-dbHostname 127.0.0.1 -dbType postgresql -schemaVersion 7-1 -dbName tigasedb -rootUser postgres -rootPass 123456           -dbUser tigase -dbPass tigase1234 -logLevel ALL
--------------------- 
作者:敢吹-敢喷-敢随-敢送 
来源:CSDN 
原文:https://blog.csdn.net/bornonew/article/details/83009028 
版权声明:本文为博主原创文章,转载请附上博文链接!

请针对你自己的数据进行设置

在这里插入图片描述

然后执行。
有问题:
在这里插入图片描述

dbType不见了。。。

查找资料可知,换个方向:
Tigase手动安装过程

封宇兄弟做过这个了,
在这里插入图片描述

直接执行sql文件—我也觉得这样虽然底层不过出错率低,

在这里插入图片描述

可以看到pg数据库的脚本不到20个,可以试一试。

创建数据库,链接数据库—ubuntu上面我用的是datagrip来链接数据库。

在这里插入图片描述

在这里插入图片描述

将所有pg脚本打开,然后查看各个sql内容,进行sql文件的执行排序。

在这里插入图片描述

最后肉眼排序可以得到执行顺序为:
额。。人家名字都帮忙排好序了,直接按照名字执行:
在这里插入图片描述

遇到的错误杂锦:

1、

postgresql-counter_data_logger-0.0.1.sql 中有错

源文件内容:

-- QUERY START:
create table tig_stats_log (
  lid            serial,
  ts             TIMESTAMP                 DEFAULT CURRENT_TIMESTAMP,
  hostname       varchar(2049)    NOT NULL,
  cpu_usage      double precision not null default 0,
  mem_usage      double precision not null default 0,
  uptime         bigint           not null default 0,
  vhosts         int              not null default 0,
  sm_packets     bigint           not null default 0,
  muc_packets    bigint           not null default 0,
  pubsub_packets bigint           not null default 0,
  c2s_packets    bigint           not null default 0,
  s2s_packets    bigint           not null default 0,
  ext_packets    bigint           not null default 0,
  presences      bigint           not null default 0,
  messages       bigint           not null default 0,
  iqs            bigint           not null default 0,
  registered     bigint           not null default 0,
  c2s_conns      int              not null default 0,
  s2s_conns      int              not null default 0,
  bosh_conns     int              not null default 0,
  primary key (ts, hostname(255))
);
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'ws2s_conns') then
       ALTER TABLE tig_stats_log ADD `ws2s_conns` INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'ws2s_packets') then
       ALTER TABLE tig_stats_log ADD `ws2s_packets` INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'sm_sessions') then
       ALTER TABLE tig_stats_log ADD `sm_sessions` INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'sm_connections') then
       ALTER TABLE tig_stats_log ADD `sm_connections` INT not null default 0;
    end if;
end$$;
-- QUERY END:

其中,primary key限制

primary key (ts, hostname(255)) 语法错误
而 判断有没有column没有就添加column的所有句子也错了,修正为:
-- QUERY START:
create table tig_stats_log (
  lid            serial,
  ts             TIMESTAMP                 DEFAULT CURRENT_TIMESTAMP,
  hostname       varchar(2049)    NOT NULL,
  cpu_usage      double precision not null default 0,
  mem_usage      double precision not null default 0,
  uptime         bigint           not null default 0,
  vhosts         int              not null default 0,
  sm_packets     bigint           not null default 0,
  muc_packets    bigint           not null default 0,
  pubsub_packets bigint           not null default 0,
  c2s_packets    bigint           not null default 0,
  s2s_packets    bigint           not null default 0,
  ext_packets    bigint           not null default 0,
  presences      bigint           not null default 0,
  messages       bigint           not null default 0,
  iqs            bigint           not null default 0,
  registered     bigint           not null default 0,
  c2s_conns      int              not null default 0,
  s2s_conns      int              not null default 0,
  bosh_conns     int              not null default 0,
  primary key (ts, hostname)
);
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'ws2s_conns') then
       ALTER TABLE tig_stats_log ADD "ws2s_conns" INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'ws2s_packets') then
       ALTER TABLE tig_stats_log ADD "ws2s_packets" INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'sm_sessions') then
       ALTER TABLE tig_stats_log ADD "sm_sessions" INT not null default 0;
    end if;
end$$;
-- QUERY END:

-- QUERY START:
do $$
begin
    if not exists (select 1 from information_schema.columns where table_catalog = current_database() and table_schema = 'public' and table_name = 'tig_stats_log' and column_name = 'sm_connections') then
       ALTER TABLE tig_stats_log ADD "sm_connections" INT not null default 0;
    end if;
end$$;
-- QUERY END:

2、postgresql-installer-create-db.sql 文件不用执行,该文件是创建数据库以及数据库的管理员账号,我们这边自己创建完毕了。

3、postgresql-installer-post.sql 文件不用执行。

4、
postgresql-server-7.0.0.sql
的内容是:

\i database/postgresql-server-7.0.0-schema.sql

\i database/postgresql-server-7.0.0-sp.sql

\i database/postgresql-server-7.0.0-props.sql

分别执行这三个文件。

5、7.1.0,8.0都是这样套路,分别执行schema,sp以及props三个文件。

全部执行之后:
在这里插入图片描述

执行xmppserver

注意,主要入口是:
在这里插入图片描述

请先在build.gradle下面添加postgresql的依赖:

 compile 'org.postgresql:postgresql:42.2.2'

然后在:
在这里插入图片描述

etc目录下面添加init.properties文件,内容复制init-mysql.properties即可。

例如:

# 新添加一个init properties
# Load standard set of the server components.
# Look at the http://www.tigase.org/configuration-wizards
# document for other possible values. Normally you don't
# need to change this line.
config-type=--gen-config-def
# List of administrator accounts, please replace them with
# administrator accounts in your installation
[email protected],admin@test-d
# The line says that the database used by the Tigase server is 'mysql'
# Look at the configuration wizards article for different options
# You can also put here a Java class name if you have a custom
# implementation for a database connector.
--user-db=postgresql
# The line contains the database connection string. This is database
# specific string and for each kind of database it may look differently.
# Below string is for MySQL database. Please modify it for your system.
# MySQL connector requires connection string in the following format:
# jdbc:mysql://[hostname]/[database name]?user=[user name]&password=[user password]
--user-db-uri=jdbc:postgresql://localhost:5432/tigase_db?user=dbuser&password=你的密码填写
# Virtual domains for your server installation, comma separated list of vhosts
--virt-hosts=devel.tigase.org,test-d
# Select what packages you want to have logging switched for
# The below setting is recommended for the initail setup and it is required
# when asking for help with setting the server up
--debug=server
# Activate HTTP API component for web based configuration and installation
--comp-name-1=http
--comp-class-1=tigase.http.HttpMessageReceiver

然后启动,错误:
在这里插入图片描述

Could not initialize tigase.db.UserRepository for name 'default'

调试得到:
在这里插入图片描述

cls之中直接是postgresql 这个类。。额,应该不是吧。

后来查到文件说明:
init.properties的配置

在这里插入图片描述

use-db应该填的是pgsql。
然后继续运行
注意:
在这里插入图片描述

每次运行xmppserver,假如没有config.tds1的话,就将从init.properties上面生成config.tds1然后将init.properties改为init.properties.old,

。。。就是说,要将config.tds1这种删除然后将init.properties.old改回init.properties才能让配置生效。

运行结果:
在这里插入图片描述

嗯,没有说postgresql找不到了。现在的问题是数据库版本的问题。。

直接找到关键字,调试一下看看:

在这里插入图片描述

implementationVersion是0.0.0.。—这个就有点可疑了。。。
我们直接写代码检查一下:

在这里插入图片描述

可以看到,implement version是0.0.0这是主因,检查这个数据在哪里来的:

在这里插入图片描述

可以追查到,获得schema version的时候已经是null,然后返回了零。

不过,package getImplemetationVersion到底是什么?

Package getImplementationVersion

在这里插入图片描述

哦。。。

这东西。。代码里面要获取 meta inf文件下面的版本号,如果没有版本号就报错---
现在是源代码开发,所以,版本号就免了吧?

好了,我的修复方式:
在这里插入图片描述

然后运行;
在这里插入图片描述

额。。。已经可以运行起来了。

所以,源代码基本运行正常了???

猜你喜欢

转载自blog.csdn.net/cdnight/article/details/85038954