Jenkins 是 Java 编写的开源持续集成(Continuous integration)工具 1。在上一篇推荐网站中提到的 AlternativeTo 中去搜索一下,能够看到很多持续集成的工具,像 GitHub 上经常看到的 Travis CI, 还有 Jenkins 的前身 Hudson。
详情请见官网.
Linux 下:
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
直接安装源中的 Package 有几点需要注意:
/etc/init.d/jenkins
。jenkins
用户来运行服务/var/log/jenkins/jenkins.log
/etc/default/jenkins
比如 JENKINS_HOME
在该文件配置http://localhost:8080
开始配置 Jenkins 吧。更多服务器 Apache , Nginx 的配置请见官网。
这里默认已经有 Android 开发环境,也就是 JDK, Android-SDK,Gradle 都已经是完整的。进入 http://localhost:8080
配置,首次今日需要验证身份信息,验证之后创建用户,然后下载插件,进入之后,系统管理 -> 管理插件,需要安装以下插件:
如有其他插件 GitHub , gitlab 啦,可以就使用环境来选择安装。
更新玩插件,进入 系统管理 ->Global Tool Configuration , 然后配置 JDK 目录, Gradle 目录,Git 目录。当然需要知道当前自己机器上的绝对地址:
系统管理 -> 系统系统设置:
Environment variables 下添加:
键 : ANDROID_HOME
值:/home/einverne/Android/Sdk
如果这一行不添加,而 Android Studio 的工程没有在 local.properties
中指定 sdk.dir=/home/einverne/Android/Sdk
的话, Jenkins build failed, cannot found Android sdk2.
配置好上面的环境,新建项目,名字 +”构建一个自由风格的软件项目”。 然后进入项目,配置
项目名字,项目描述, GitHub Project url。 如果想要自定义路径,可以在高级中设置。
当然使用的是 Git, 然后是项目地址,然后需要验证身份信息,当然有很多的方式,用户名密码,用户名密钥,等等,根据自己的适用情况添加即可。可以选择分支 build.
这里可以选择何时触发构建, 有很多的方式,可以是有变动自动构建,也可以是定时构建,当然也有很多的触发方式。
这边基本上在全局环境配置的时候就已经满足,细化一下 build 环境。
这里需要选择 Invoke Gradle script
, 然后在配置中选择刚刚在全局配置中配置的 Gradle 版本。
在 Tasks 下输入 clean build
.
Publish Android Lint results
, 以便输出 Lint 结果,设置中输入 **/lint-results*.xml
.Archive the artifacts
来存档 apk 文件,设置中输入 **/*.apk
。 默认输出文件在 Workspace 下 app/build/outputs/apk/
。Jenkins 默认启用 Lint 检查,所以需要在 build.gradle
中 android
下添加
lintOptions {
abortOnError false;
}
图文教程,Windows 下教程参考下面文章。
总说“授人以鱼不如授人以渔”,寻找不同平台上的代替品,每次都会点进这个网站,或许是上一段时间内跨不同操作系统太频繁,所以导致寻求Mac下 Windows 某个软件的代替品的需求升高,现在渐渐的培养起自己只使用多平台客户端都存在的应用使用,而有些是在没有Linux下的应用,也尽量的能够找到功能相似的代替。所以 AlternativeTo 这个网站给我带来了很多的便利。
官网地址:http://alternativeto.net/
应用实例:
My Tracks 原本是Google推出Android上记录GPS轨迹的应用,在很早开始就一直使用,无奈Google宣布停止这款应用,而自身推出的 Fit 功能上也赶不上 My Tracks,想到这里真心感觉有点讽刺,几年后推出的产品在功能上竟然赶不上几年以前推出的应用。Google Photos 与 Picasa 也是。说偏了,回到 My Tracks, 直接访问 http://alternativeto.net/software/my-tracks/ 就能够找到很多的应用,上面有些用户也会给出功能的对比,有所少人喜欢某个应用,在几乎所有的情况下,排名第一的几乎就是最好用的了。
有的时候多逛一逛这个网站能够有不少收获,就比如早之前我一直用的 KMPlayer , 而自某一个版本开始 KMPlayer 开始变得臃肿,收纳很多无用的功能之后,就可以到 KMPlayer 的 alternativeTo 来寻求代替品,最后会发现 PotPlayer 也非常好用,然后我一直使用至今。当然在 Linux 下就又可以跑到 PotPlayer 下面,然后找到 MPlayer 和 SMPlayer ,都非常不错,当然 VLC Media Player 也很棒。
当然还有很多很多的例子,都需要慢慢的发现,我曾经在上面找过 IDE 的代替品,找过编辑器的代替品,找过 SQLite Manager 的代替品,等等,他最好最方便的功能就是,当你在一个平台已经养成了一个使用习惯,突然间更换了一个平台,然后对这个环境很陌生,而在这个网站的指导下就能够迅速的找到代替品。快速的适应新的环境。而这样引出来的另一个问题就是,需要熟悉不同的工具。所以就回归到我之前所说,我几乎现在只考虑使用三个平台 Windows, Mac, Linux 下都存在产品的应用了。虽然现在像 Evernote,网易云音乐同样没有Linux客户端,但这已经是非常少的特例了。使用同样的应用,同样的环境才能提高效率,并且不同去适应不同的工具的差异。
Linux 中的 ps 命令是 Process Status 的缩写。ps 命令用来列出系统中当前运行的那些进程。ps 命令列出的是当前那些进程的快照,就是执行 ps 命令的那个时刻的那些进程,如果想要动态的显示进程信息,就可以使用 top 命令。
要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程,而 ps 命令就是最基本同时也是非常强大的进程查看命令。使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵死、哪些进程占用了过多的资源等等。总之大部分信息都是可以通过执行该命令得到的。
ps - report a snapshot of the current processes.
ps 提供的是执行时刻进程的状态,它提供的结果不是动态连续的;如果想对进程进行连续监控,应该用 top/htop
工具。
Linux 上进程有 5 种状态:
ps 工具标识进程的 5 种状态码:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
ps --help all
Usage:
ps [options]
Basic options:
-A, -e all processes
-a all with tty, except session leaders
a all with tty, including other users
-d all except session leaders
-N, --deselect negate selection
r only running processes
T all processes on this terminal
x processes without controlling ttys
Selection by list:
-C <command> command name
-G, --Group <gid> real group id or name
-g, --group <group> session or effective group name
-p, --pid <pid> process id
--ppid <pid> select by parent process id
-s, --sid <session> session id
-t, t, --tty <tty> terminal
-u, U, --user <uid> effective user id or name
-U, --User <uid> real user id or name
selection <arguments> take either:
comma-separated list e.g. '-u root,nobody' or
blank-separated list e.g. '-p 123 4567'
Output formats:
-F extra full
-f full-format, including command lines
f, --forest ascii art process tree 显示进程间关系
-H show process hierarchy 显示树形结构
-j jobs format
j BSD job control format
-l long format
l BSD long format
-M, Z add security data (for SE Linux)
-O <format> preloaded with default columns
O <format> as -O, with BSD personality
-o, o, --format <format>
user defined format
s signal format
u user-oriented format
v virtual memory format
X register format
-y do not show flags, show rrs vs. addr (used with -l)
--context display security context (for SE Linux)
--headers repeat header lines, one per page
--no-headers do not print header at all
--cols, --columns, --width <num>
set screen width
--rows, --lines <num>
set screen height
Show threads:
H as if they where processes
-L possibly with LWP and NLWP columns
-m, m after processes
-T possibly with SPID column
Miscellaneous options:
-c show scheduling class with -l option
c show true command name 显示进程真实名称
e show the environment after command
k, --sort specify sort order as: [+|-]key[,[+|-]key[,...]]
L list format specifiers
n display numeric uid and wchan
S, --cumulative include some dead child process data
-y do not show flags, show rss (only with -l)
-V, V, --version display version information and exit
-w, w unlimited output width
--help <simple|list|output|threads|misc|all>
display help and exit
For more details see ps(1).
ps aux
a
显示所有用户的进程u
显示进程的所有者x
显示非终端启用的进程输出:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 10656 668 ? Ss Apr12 1:14 init [2]
root 2 0.0 0.0 0 0 ? S Apr12 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Apr12 4:28 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Apr12 0:00 [kworker/u:0]
说明:
ps -A
输出:
PID TTY TIME CMD
1 ? 00:01:20 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:13 ksoftirqd/0
5 ? 00:00:00 kworker/0:0H
7 ? 00:17:02 rcu_sched
8 ? 00:00:00 rcu_bh
9 ? 00:00:03 migration/0
10 ? 00:00:02 watchdog/0
ps a -u root
ps -ef
ps aux
ps -ef | grep ssh
输出:
ps -ef | grep ssh
root 18928 22845 0 21:10 ? 00:00:00 sshd: root@pts/4
root 19852 20288 0 21:25 pts/2 00:00:00 grep ssh
root 22845 1 0 Jun18 ? 00:00:32 /usr/sbin/sshd
ps -l
输出:
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 17398 17394 0 75 0 - 16543 wait pts/0 00:00:00 bash
4 R 0 17469 17398 0 77 0 - 15877 - pts/0 00:00:00 ps
各相关信息的意义:
在预设的情况下, ps 仅会列出与目前所在的 bash shell 有关的 PID 而已,所以,当使用 ps -l 的时候,只有三个 PID。
ps -axjf
输出:
PPID PID PGID SID TTY TPGID STAT UID TIME COMMAND
0 2 0 0 ? -1 S 0 0:00 [kthreadd]
2 3 0 0 ? -1 S 0 4:28 \_ [ksoftirqd/0]
2 5 0 0 ? -1 S 0 0:00 \_ [kworker/u:0]
2 6 0 0 ? -1 S 0 0:00 \_ [migration/0]
1 20287 20287 20287 ? -1 Ss 0 0:01 SCREEN -S lnmp
20287 20288 20288 20288 pts/2 19855 Ss 0 0:00 \_ /bin/bash
20288 19855 19855 20288 pts/2 19855 R+ 0 0:00 \_ ps -axjf
ps aux | grep '(cron|syslog)'
输出:
root 2682 0.0 0.0 83384 2000 ? Sl Nov02 0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
root 2735 0.0 0.0 74812 1140 ? Ss Nov02 0:00 crond
root 17475 0.0 0.0 61180 832 pts/0 S+ 16:27 0:00 egrep (cron|syslog)
ps -o pid,ppid,pgrp,session,tpgid,comm
PID PPID PGRP SESS TPGID COMMAND
17398 17394 17398 17398 17478 bash
17478 17398 17478 17398 17478 ps
组合 sort 和 head 使用:
ps aux | sort -nrk 3,3 | head -n 5
ps aux | less
ps aux > /tmp/ps.txt
Recently, I have worked on a C++ project create by eclipse using CDT. And I generate my .gitignore
file at gitignore.io. However when I shared my project to Git, and want to import my project on other computer. I find I cannot import my Exist project into Eclipe workspace.
After I did search, I notice that my gitignore file just ignore .project
file which has an annotation says that it’s Eclipse Core. I found that each time Eclipse want to import an exist project. Eclipse will try to find this file. The eclipse documentation states the porpuse of .project
file as follow:
The purpose of this file is to make the project self-describing, so that a project that is zipped up or released to a server can be correctly recreated in another workspace.
and
If a new project is created at a location that contains an existing project description file, the contents of that description file will be honoured as the project description. One exception is that the project name in the file will be ignored if it does not match the name of the project being created. If the description file on disk is invalid, the project creation will fail.
So I decide to not ignore .project
in git version control. And remove the .project
ignore in .gitignore
file. After that it is easy for me to import project into Eclipse.
I followed @lanoxx’s idea to keep .project
file under git version control. So after you cloned your repository on other place, you can simply use Import -> Existing Project from Workspace. Eclipse will take care the .project
file and recreate other project related config files for you, like .cproject
under C++ project, and .classpath
or .settings/
under java environment.
If you do not share the .project
file, then it is not possible to import the project with Eclipse. You will need to create a new project with the project wizard first, and then you can choose import “General->File System”, this will copy all the files into your workspace. This is probably not what you want, because it means that you cannot clone the git repository into the workspace, you must clone it somewhere else and then import it from there. Therefore you should always share the .project file.
About all, I talk about the .project
file. Following I have done a little search for the .cproject
. This file contain all the settings provided for the particular selected Toolchain. For example, if the project needs to be created with gcc, then this .cproject file will contain all the compiler, linker options used by gcc. This file is also important to reimport the project. All your settings in project properties will remain if you choose to keep this file under track.
try-with-resources 表达式就是在 try 语句中定义了一个或者多个资源,resource 必须要在程序结束后关闭,try-with-resources 表达式保证了 resource 会在表达式结束时自动关闭,有点像 python 的 with 语句。所有实现了 java.lang.AutoCloseable
接口的类都可以作为 try 中的 resource。
下面的例子中 BufferedReader
需要被关闭。在 Java SE 7 以后,BufferedReader 实现了 AutoCloseable 接口,所以定义在 try 语句中的的 br 对象,不管正常执行,或者异常,都会在表达式结束时自动关闭。
static String readFirstLineFromFile(String path) throws IOException {
try (BufferedReader br =
new BufferedReader(new FileReader(path))) {
return br.readLine();
}
}
在 Java SE 7 以前需要使用 finally 来保证
static String readFirstLineFromFileWithFinallyBlock(String path)
throws IOException {
BufferedReader br = new BufferedReader(new FileReader(path));
try {
return br.readLine();
} finally {
if (br != null) br.close();
}
}
当然在 try 语句中多个语句也是可以的。
如果要实现 try-with-resources
需要资源实现 AutoCloseable
接口,重写 close
方法。
然后 Java 程序在编译的时候,编译器就会根据实现的 close 方法来自动生成 try-finally 方法块。
Closeable 继承了 AutoCloseable:
public interface Closeable extends AutoCloseable {
void close() throws IOException;
}
Closeable 的 close 方法抛出的是 IOException
.
OpenSSH 毫无疑问是世界上使用最广泛允许用户通过终端安全连接远程主机的工具了,但是 OpenSSH 存在一个比较大的问题就是不能在多台主机中执行相同的命令,OpenSSH 并不是设计做此用途的。所以 Parallel SSH 或者简称 PSSH 就出现了。PSSH 是一个 python 编写的用来在多台主机中并行执行相同命令的工具。
PSSH 工具集包含如下命令:
sudo apt install python-pip
sudo pip install pssh
首先创建 pssh host 文件
192.168.0.10:22
192.168.0.11:22
比如执行 echo
pssh -h pssh-hosts-file -l root -A echo "TEST"
比如查看硬盘使用情况
pssh -h pssh-hosts-file -l root -A -i "df -hT"
同理
pssh -h pssh-hosts-file -l root -A -i "uptime"
PSSH 工具适合用来在管理员需要在多台主机上执行重复命令时。
最近在安装 Resilio Sync 的时候发现,竟然被屏蔽了,官网被屏蔽了竟然连 key 都下载不了,可以使用之前写过的 proxychains 代理 来使用代理下载这个 key。
惊闻 btsync 已经改名字,现在叫 Resilio Sync ,官网地址也改为: https://www.resilio.com/
可以从 这里 获取不同平台客户端。
Linux 安装 Package 可以参考 https://help.getsync.com/hc/en-us/articles/206178924 这里
创建文件 /etc/apt/sources.list.d/resilio-sync.list
, 添加如下内容:
deb http://linux-packages.resilio.com/resilio-sync/deb resilio-sync non-free
添加公钥:
wget -qO - https://linux-packages.resilio.com/resilio-sync/key.asc | sudo apt-key add -
安装:
sudo apt-get update
sudo apt-get install resilio-sync
配置文件存储地址 https://help.getsync.com/hc/en-us/articles/206664690
Linux 下配置文件地址:/var/lib/resilio-sync
啊,安装好了之后,添加这个 key,当个示例啦 BB63I5PBPBFDELAPXI6NTF47IPNZQAAJZ
,一周一本好书。
如果想要手动开启或者关闭 Resilio Sync 可以使用如下命令:
sudo service resilio-sync stop
sudo service resilio-sync start
全称 BitTorrent Sync , 我习惯了叫他 btsync 了。想要了解他的前世今生直接去看维基百科 就好了。一句话概括,他就是一个同步工具,类 Dropbox,但是利用 P2P 等等 bt 种子的技术。当然私人使用当成网盘工具也好,当成分享工具也好,看个人使用了。不过黑客提醒,虽然是去中心化的,但是安全性依然存在问题,最好不要传输私人信息。
官网地址: https://www.getsync.com/
现在使用任何一个工具或者服务,我首要考虑的问题离不开跨平台了,最好是 Windows , Linux, Mac 下全部都有,不然在平台间来回切换不同的服务和工具时间成本,学习成本太高了。也正是因为这个原因我放弃了 Google Drive 而转用 Dropbox,作为主力同步工具。当然 btsync 在全平台都有客户端,甚至连一些 NAS,路由器设备都有。
安装非常简单,去官网下载,下一步下一步,OK。当然 Linux 下,如果不想使用 下一步下一步安装法,也可以使用命令从 PPA 里拖。
sudo add-apt-repository ppa:tuxpoldo/btsync
sudo apt-get update
For normal desktop use, you only need to install btsync-user
:
sudo apt-get install btsync-user
Alternatively, if you’re setting up your BTSync server, install btsync
:
sudo apt-get install btsync
在官网根据自己的机器选择合适的 client 下载并解压。并运行:
./btsync
即可。
默认的 Web GUI 地址是 : http://127.0.0.1:8888
更加详细的安装指南可以参考这篇
类似 Linux 下安装,官网下载并解压 btsync 文件。
tar -zxvf BitTorrent-Sync_x64.tar.gz
然后执行:
./btsync --dump-sample-config > btsync.conf
创建配置文件,然后修改 btsync.conf
配置文件中的:
"listen" : "0.0.0.0:8888"
还有 login
和 password
, 端口默认是 8888,可修改成其他没有冲突的。login
和 password
是登陆用户名和密码。其他配置看注释修改即可。参考官网 config 文章.
然后保存配置文件,启动:
./btsync --config btsync.conf
在浏览器中就能够在 http://ip:port/ 访问 Web GUI。
然后在本地获取同步 key ,和 VPS 上同步即可。
如果你已经同步了一个文件夹,比如在 ~/books
,现在想要将该同步的目录移动到 ~/btsync/books
目录下。 就像 Dropbox 同步已经存在的文件夹 一样,如果单纯的再重新下载一边太麻烦了。所以幸好 btsync 和 dropbox 都有这样的性质,同步的内容都有文件记录,将文件重新加入索引,等索引完之后就可以继续和其他的文件同步了。
默认 btsync 的 web gui 是没有启用加密的,如果想要使用 https://ip:port/gui 来访问,则需要使用 config 配置,并在 config 配置中设置 force_https
, ssl_certificate
,ssl_private_key
,然后重启 btsync 。
如果觉得这样让 btsync 直接获取证书不安全,这里 还有另外一种配置,利用 nginx 的代理。
Andy 整理的电子书,大概 100G 左右 B2YZTLQJYCRWAM4LJLWBZWH7EEYU25J3T
57G ./Andy 收集
3.4M ./_gsdata_
23G ./kindlefere
5.2G ./kindleren 精品资源(一)
3.2G ./kindleren 精品资源(二)
11G ./mebook
21G ./suguniang01
5.5G ./suguniang02
6.2G ./ 其他 sync 资源
848M ./ 子乌书简
13G ./ 整理 3200
144G .
最近迷上了360度全景,搞了得图800,和理光 theta m15的全景相机玩。然后就对周边的全景处理App都体验了一下。最早接触到 Sphere Photo 也要归功于 Google 的原生 Camera, 然而因为不知道的原因,在 Android kitkat 之后的版本中这个小行星视图就消失不见了。而我还是依然很怀念这样的视图。下面就是一些 Play Store 中存在的制作小行星视图的App。
完整却不够完美 市场上唯一一款收费的小行星app,但是给我的感觉却是做的不够精致和完美,今天竟然处理出不完整的人脸。处理图像甚至比不上另一款免费的app。
除了开始的广告一切还好 开始的广告可能是让很多人打低分的原因,但是这款app,确实达到了我的需求,并且实现的很好。开发者可以尝试提供pro版本来去除广告或者内购去广告。
广告多功能简单 太多影响操作的广告,横幅广告侵占了操作预览区域。功能比不上其他app。
功能简单广告影响使用 功能几乎没有,处理时间太长。广告占据太多篇幅。
最后推荐 Little Planet , 虽然在App开始出现了全屏广告,但是效果及功能和收费的 Tiny Planet FX Pro 相差不大。
大多数时候我没有时间用 Google Camera 照完整个全景,这个时候如果可以后期合成当然是最好的,于是就有了这样一篇文章 ,只要有一张全景照片,利用 Photoshop 同样可以实现 Sphere Photo。 同样也可以参考这篇文章。
最后推荐一个社区 https://plus.google.com/u/0/communities/115970110085205516914 ,社群的简介里面有很多教程,并且分享的 Post,质量都很高。
The Web Server Gateway Interface(WSGI) 是网络服务器软件和网络应用程序之前的标准接口。通过共同的网关标准接口可以让同一个应用支持不同的服务器。只有网络服务器或者编程框架的作者需要熟悉 WSGI 设计,如果使用现存的框架则不太需要关心更底层的网关接口。
wsgiref 是 Python 的 WSGI 标准实现,可以用来帮助实现网络服务器和应用框架。他提供了一系列工具用来操作 WSGI 环境变量和响应头,也提供了基础的类来实现 WSGI 服务器,提供了简单的 HTTP 服务来给 WSGI 应用提供服务器,提供了一个符合 WSGI 标准(PEP 3333) 的验证工具来验证 WSGI 服务器和应用。
文档
wsgiref.util 这个模块提供了一系列工具用来操作 WSGI environments。
该模块提供了一个简单的类 Headers
用来操纵 WSGI 相应头。
该模块基于 http.server 实现了一个简单的 HTTP 服务器,这个服务器能够给 WSGI 应用提供服务。每一个服务器实例在特定的 host 和 port 上提供一个 WSGI 应用服务。如果要在听一个 host 和 port 上给不同应用程序提供服务,那么你需要创建一个 WSGI 应用,并且传入 PATH_INFO
来选择哪一个应用程序来来被每一次请求调用。
验证模块。
该模块提供了实现 WSGI 服务器和网关的基础类。这些基础类能够处理和 WSGI 应用的大部分通信。
简单的例子
from wsgiref.simple_server import make_server
# Every WSGI application must have an application object - a callable
# object that accepts two arguments. For that purpose, we're going to
# use a function (note that you're not limited to a function, you can
# use a class for example). The first argument passed to the function
# is a dictionary containing CGI-style environment variables and the
# second variable is the callable object (see PEP 333).
def hello_world_app(environ, start_response):
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
start_response(status, headers)
# The returned object is going to be printed
return [b"Hello World"]
httpd = make_server('', 8000, hello_world_app)
print("Serving on port 8000...")
# Serve until process is killed
httpd.serve_forever()
MyBatis 自动生成的 Java client generator 会产生如下的方法;
前面一些方法看名字都能知道其用法,但是有些还是有些模棱两可。比如 withBLOBs 和 没有 BLOB 方法的区别。
如需检索的字段中包含大字段类型时,必须用 selectByExampleWithBLOBs,不检索大字段时,用 selectByExample 就足够了。update 同样如此。
MyBatis GeneratorXML 配置文件在大多数情况下由 XML 配置提供。文件会配置 MyBatis Generator :
下面是基础的模板
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<classPathEntry location="/Program Files/IBM/SQLLIB/java/db2java.zip" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<jdbcConnection driverClass="COM.ibm.db2.jdbc.app.DB2Driver"
connectionURL="jdbc:db2:TEST"
userId="db2admin"
password="db2admin">
</jdbcConnection>
<javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<javaModelGenerator targetPackage="test.model" targetProject="\MBGTestProject\src">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="test.xml" targetProject="\MBGTestProject\src">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="test.dao" targetProject="\MBGTestProject\src">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >
<property name="useActualColumnNames" value="true"/>
<generatedKey column="ID" sqlStatement="DB2" identity="true" />
<columnOverride column="DATE_FIELD" property="startDate" />
<ignoreColumn column="FRED" />
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />
</table>
</context>
</generatorConfiguration>
<context>
元素用来定义生成 Object 的环境,子元素用来定义数据库连接方式,生成对象的类型,和需要生成的 table. 多个 <context>
标签可以配置在 <generatorConfiguration>
下,允许配置多个数据库连接。
顾名思义,连接数据库配置
<plugin>
下定义一些插件,这些插件用来扩展或者修改 MyBatis Generator 生成的代码。plugin 是 context 的子元素。
generatorConfiguration 配置,文档地址这里,每个子元素文档都存在。
这个标签用来配置 MySQL 数据类型到 Java 类型转换过程的精度,比如使用 forceBigDecimals
那么就是默认尝试使用 java.math.BigDecial
来处理 Decimal 和 Numberic 字段。