tigase相關參考資料--linux+tigase+postgresql 二次開發環境搭建【草稿】
參考資料
配置【草稿-試錯】
獲取原始碼
下載原始碼到特定目錄:
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],[email protected]
# 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檔案下面的版本號,如果沒有版本號就報錯---
現在是原始碼開發,所以,版本號就免了吧?
好了,我的修復方式:
然後執行;
額。。。已經可以執行起來了。
所以,原始碼基本執行正常了???