Utilize shell scripts,linux commands, open source tools,java, to Maximize the Power of Linux.
Focused on working with linux and shell, search engine technology including Chinese segmenter
Any questions please contact me at gmail: david.ullua

5/31/2007

Utilize hudson and ant to set up a daily build system step by step

Hudson is popular daily build system and a continuous integration engine. It is easy to setup and maintenance. Here's the brief introduction of the deploy process:

0). download hudson from https://hudson.dev.java.net/servlets/ProjectDocumentList.
You can download jnlp release jar or old release war package.

1).Hudson needs a web container such as glassfish, tomcat or winstone.
But Hudson ships with Winstone, so you can run it standalone by run : java -jar hudson.war, or java -jar hudson.jar if you downloaded the jnlp release.

Use the -D option to specify HUDSON_HOME in the invocation:
$ java -DHUDSON_HOME=/path/to/home -jar hudson.war

Alse you can use the environment variable:
$ export HUDSON_HOME=/path/to/hudson_home
$ java -jar hudson.war

HUDSON_HOME: Hudon needs some diskspace to perform builds and keep archives.
(By default, this is set to ~/.hudson , but you can change it: https://hudson.dev.java.net/admin.html)

2).If you don't have container yet, you can run hudson standalone (with shipped container Winstone), then you can access the portal of hudson by http://hostname:8080/ (default port is 8080), and create a new job, set some basic configurations. it will run by the schedule you configured.

3).If you have a container already (like tomcat), just deploy hudson.war to the webapps directory of tomcat, restart tomcat. then you can access the portal from http://hostname:8081/hudson, assume 8081 is the port for tomcat. for glassfish please take a reference at https://hudson.dev.java.net/containers/glassfish.html.

4). you can configure automatic build (like crontab), or periodical build or build by email, ref: https://hudson.dev.java.net/build.html

5). if you met problem when run ant task (), make sure your ant target is correct. My ant target is "-f CustomBuild.xml makepackage", it runs makepackage in ant build file CustomBuild.xml. If still fails, you can just checkout your project from repository to a clean directory, and run ant command to check whether it runs through, if fails check ant build file.

6).if can't send email successfully, just click "Manage Hudson" in the index page of the hudson portal, click "System Configuration" to configure smtp related info. If your SMTP need authentication, click "Advanced" in the "E-mail Notification" section, and enter the username plus password.

It should works, else email me your problem.

5/28/2007

gains of subversion (SVN带来的收益)

Author: David Lv Euler
Date: 05/28/2007, Suzhou

When I working on .Net and VSS. Our team was often troubled by the crippled VSS. In many cases, someone modified a common file like DbHelper.cs, or a business logic class Order.cs, and we need to modify the file too. Then we need to wait for him/her to checkin/commit the file, even worse, he/she is taking a vacation in another city, then we have to modify the file's read-only attribute on local disk, however could not checkin/commit the changes. It wasted us lots of time in waiting and in checkin/checkout.

If you are suffering from "lock, checkout and modify" model of VSS (Visual Source Safe) in team cooperation, or you are searching for a version control system, I suggest you to try subversion (SVN) as source management system. Subversion has a model of "checkout, modify, update and commit". After checkout a file/folder, anyone can modify a file in the same time, then when execute updating(if no concurrent modification you don't need to update, just commit directly), svn will merge other's modification to your working copy automatically, then you can commit your copy safely. If it can't merge these modifications, it would tell you where are conflicts, and you can resolve them manually and then commit safely. you can reference the manual in http://subversion.tigris.org .

Even if you are using dotnet, there is subversion plugins for VS.net. Now my team are using java, SVN has helped us in source code management and team cooperation greatly. I believe that it is one of the most successful open source project.

当我使用.net和VSS的时候,我们的团队经常被憋足的VSS所绊倒。很多情况下,有人修改了一个公用文件DbHelper.cs 或者一个业务逻辑文件Order.cs, 这时我们也需要修改这个文件。然后我们不得不等他/她签入/提交文件。更糟糕的是,此时他/她可能正在另一个城市旅行,这时我们只好修改本地文件的只读属性,但依然无法签入。大量的时间在等待和签入签出中被浪费了。

如果您正在被VSS的“锁定,签出,修改”模型所困扰,或者您正在寻找一个版本管理系统,那么我向您推荐subversion (SVN). Subversion使用"签出,修改,更新和提交"的模型,当签出一个文件或目录后,每一个人都可以同时修改同样的文件,然后执行更新(如果没有并发修改就不需要更新,可以直接提交), svn会自动合并其他人的修改到您的工作文件中.然后您可以安全地提交您的机器上的拷贝. 如果svn无法合并更改,那么她会告诉您哪些地方有冲突,您可以手工解决这些冲突,然后安全地提交. 您可以参考http://subversion.tigris.org 上面的手册.

即时您在使用dotnet, 仍然有VS.net的subversion插件可以使用。现在我的Team使用java, SVN在代码管理和团队协作上给了我们很大的帮助。我相信她是最优秀的开源项目之一。

5/09/2007

"You can't load TkCximage", could not run amsn as normal user

gaim or Kopete would miss lots of messages. what's the most worse is file transfer often fails. so i tried amsn under linux as MSN messenger.

I download amsn 0.96 from linuxpackages for the slack package.
First time when i run ./amsn, it said "exec wish" failed, then I googled and installed TCL/tk in the slackware 11 second ISO file.

Then run ./amsn, it said could not find ComboBox, oh, then googled and find that the package is installed by root, and normal users does not have the rights of /usr/share/amsn/utils/combobox. So I chown the rights to a normal user. Still, it said "You can't load TkCximage, this is now needed to run aMSN. please compile amsn first..." , oh, God, the cause is /usr/share/amsn/ and all it's sub-directories doesn't have the execute permission, so can't load TkCximage.

Then I logged in xfce as root , run amsn, it works. So I tried to give all subdirectories under /usr/share/amsn/ with execute permission, ( add execute permission for all subdirectories under folder ):
#cd /usr/share/amsn/
#find ./ -type d -exec chown david.users {} \;
#find ./ -type d -exec chmod +x {} \;

then logged as normal user david, run ./amsn, it works now.

4/09/2007

mysql error -- /etc/rc.d/rc.mysqld restart

in Slackware 11, when i connect mysql (5.0.24a) by ip/remotely:

$mysql -u roboo -h 172.16.100.30 -p

error showed as following:
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.100.30' (111)

i googled around, someone said can edit the my.cnf , comment this line:
skip-networking
but there isn't any my.cnf on the file system. even type locate my.cnf,nothing
happened, i got stuck on the problem. then tried to find which configuration
file (my-huge.cnf, my-large.cnf, my-medium.cnf, my-small.cnf ?) mysql is
using, and didn't find anything in /usr/bin/mysqld-safe. however, find
something useful by ps command:

$ps aux|grep mysql
root 3896 0.0 0.0 2328 432 ? S 08:56
0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysql/mysql.pid --skip-networking
mysql 3921 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
mysql 3922 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
mysql 3923 0.0 0.5 52840 5416 ? S 08:56
0:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysql/mysql.pid --skip-locking --skip-networking
.....

yes,--skip-networking is the key.it means when mysqld is started,
a "--skip-networking" parameter is passed. I opened /etc/rc.d/rc.mysqld ,
and see this line:
SKIP="--skip-networking"

and in the later lines SKIP is taken as a parameter of mysqld. so comment the
SKIP line, restart mysqld.
#/etc/rc.d/rc.mysqld restart

it works!

3/31/2007

how to package jar easily with find command

Eclipse jar packing function isn't very easy and comfort to use. Sometimes the packaged jar does not include some classes.

we can use find and jar command to make a jar package easily:
assume $project is where your project located, and bin is the output directory.
com.xxx.yyy is the parent package of the project.

cd $project/bin
find ./com  > classlist  (or find ./com -name *.class if you have .cass files only)
jar -cvf project.jar @classlist

2/04/2007

Shell Programming FAQ(为什么shell脚本无法运行?)

上 个月在CU(ChinaUnix)的论坛上看到有人贴出帖子说在shell下面运行不了if...else语句,而且还大骂linux说linux连最简 单的事情都做不了。这几天写了几个脚本处理日常工作,也遇到一些问题,也许CU论坛上骂linux的这位仁兄,也是因为遇到类似的问题,所以才会骂 linux。总结一下常见的问题如下,其中涵盖有赋值表达式,逻辑运算符(if),命令替换,环境变量设置(export)等,希望对初学shell编程 的朋友有所帮助。有任何问题可在论坛上联系我,或者email到david.ullua at gmail。 -- David Euler,2006/12/14

Q1.我在shell脚本中加入如下:i = 1 ,运行的时候脚本报错,难道shell下面不可以对变量赋值吗?
A1.赋值运算符前后不可以有等号=。试试i=1

Q2.我再shell上运行i=1;i++报错"-bash: i++: command not found", 运行i=1;i=i+1;echo $i 结果不是2,而是"i+1", shell如何支持算术运算呢?
A2.i++的表达方法在shell中是不被支持的;表达式的右边引用变量,变量名前面要加$;表达式求值时表达式要用$((expression))的形式把表达式expression括起来。所以正确的是:
i=1;i=$(($i+1));echo $i

Q3.我需要设置JAVA_HOME变量,于是按照一些教程,使用下面命令,为什么会报错?是不是shell不兼容?
export JAVA_HOME = /working/jdk1.5.0_09
A3.试试
export JAVA_HOME=/working/jdk1.5.0_09, 两个有什么区别呢,前面的=前后多了1个空格,shell下面=作为赋值运算符时前后不可有空格

Q
4.我按照教科书上说的使用命令替换,把date命令的运行结果保存到DATE变量,DATE='date';echo $DATE; 可运行结果是:date, 而不适date命令的结果。
A4.命令替换是要用后引号(`,Shift+~)而不是单引号把命令括起来。 运行DATE=`date`;echo $DATE; 试试


Q5.我运行if 语句来测试逻辑表达式:
if[ "$SHELL"="/bin/bash" ]; then echo "bash";fi
中括号[]的前后都用了空格,为什么还会报错呢?
A5.上面的shell句子有两处语法错误:if后面也需要有空格;等于号"="作为逻辑运算符时,前面和后面都必须要有空格,否则会被shell作为赋值表达式,linux下面赋值运算符与逻辑运算符等于都用"="表示,区别在于前后有无空格。正确的如下:
if [ "$SHELL" = "/bin/bash" ]; then echo "bash";fi


使用fdisk -l 快速查找可用的移动设备(移动硬盘,优盘,SD/MMC卡等)

插入移动硬盘或者优盘以后,对于不一样的USB设备,不一样的机器,移动硬盘(或优盘)在系统中的设备标识(/dev目录下的链接)都是不一样的。

有时候是在/sdb1下面,有时候是在/sdc1, 或者/sda5下,也可能是其他的路径标识。在尝试了"mount /dev/sdxn /mnt/udisk" 3次,5次都没有找到后,任何人都可能感觉到泄气。

其实在我们可以用fdisk -l (注意是小写的-L,list的意思) 命令查看系统的所有存储设备信息。fdisk是磁盘格式化工具,所以在磁盘,包括移动存储设备还没有mount的时候,就可以检测到这些设备。

下面是我的电脑插上优盘约30秒(接上优盘后,会有片刻的检测时间)后,运行fdisk -l的结果:
Disk /dev/sda: 512 MB, 512229376 bytes
9 heads, 8 sectors/track, 13895 cylinders
Units = cylinders of 72 * 512 = 36864 bytes

Device Boot Start End Blocks Id System
/dev/sda1 4 13896 500107+ 6 FAT16

Disk /dev/hda: 80.0 GB, 80023182848 bytes
255 heads, 63 sectors/track, 9728 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1736 13944388+ 7 HPFS/NTFS
/dev/hda2 1737 9729 64203772+ f W95 Ext'd (LBA)
/dev/hda5 1737 2884 9221278+ b W95 FAT32
/dev/hda6 2885 3648 6136798+ 83 Linux
/dev/hda7 3649 8512 39070048+ 7 HPFS/NTFS
/dev/hda8 * 8513 9156 5172898+ 83 Linux
/dev/hda9 * 9157 9666 4096543+ 83 Linux
/dev/hda10 9667 9729 506016 82 Linux swap

这里可以看到/dev/sda1是有盘,可以mount /dev/sda1 /mnt/udisk加载u盘。

JAVA (JDK 1.5, slackware/debian linux)中文显示乱码问题的解决

我用的是slackware, jre的版本是1.5.0_09, 按jhuangjiahua的方法java应用程序的乱码问题可以解决。


标题: 再提 Ubuntu/Debian 下 JAVA 中文显示 作者:jhuangjiahua
来自:http://www.linuxsir.org/bbs/

IRC 上又有朋友问到这 JAVA 的 ,

1.
在 jre/lib/fonts/ 下建立个目录 fallback
比如我这儿就是
mkdir /usr/lib/j2sdk1.5-sun/jre/lib/fonts/fallback/

2.
在 fallback 里弄个中文字体
拷贝或链接都可以

比如我这就是
ln -s /usr/share/fonts/truetype/arphic/uming.ttf /usr/lib/j2sdk1.5-sun/jre/lib/fonts/fallback/


3.
进入 jre/lib/fonts/fallback/ 执行 mkfontscale
再把 jre/lib/fonts/fonts.scale 的内容加到 jre/lib/fonts/fonts.dir

我这儿就是
cd /usr/lib/j2sdk1.5-sun/jre/lib/fonts/fallback/
mkfontscale
cd ..
cat fallback/fonts.scale >> fonts.dir


原文地址 http://www.linuxsir.org/bbs/

2/02/2007

Apache 2.2.4, tomcat5.0.28 整合,以及中文乱码问题解决

Author: David Euler, 2007, david.ullua _at_ gmail (请用gmail.com替换gmail)

这篇文章主要参考从google搜索到的整合方法和问题解决方法,以及apache.org官方网站的文档。

并经过实际的验证 (os: slackware 11, 软件版本参考安装)。

目录

I.安装Apache, Tomcat, tomcat-connector (mod_jk) , 并整合apache与tomcat

II.tomcat, apache整合后,去掉tomcat的8080端口服务,用户只能通过80端口访问服务器

III.Tomcat/Apache乱码问题解决.

IV.虚拟主机配置

---------------------------------------------------------------------------------------------------------------

I.安装Apache, Tomcat, tomcat-connector (mod_jk) , 并整合apache与tomcat

共分5个步骤,详述如下

1、准备,下载需要的文件。这里假定你已经正确安装配置好了JDK。

到Apache官方网站下载所需要的文件:

httpd-2.2.4.tar.gz , apache的httpd server包 (需要编译安装,安装时)

apache-tomcat-5.5.20.tar.gz, apache的tomcat包, 不需要编译安装(解压即可)

tomcat-connectors-1.2.20-src.tar.gz (mod_jk的安装包)

2、安装Apache。

# tar xzvf httpd-2.2.4.tar.gz

或 tar jxvf httpd-2.2.4.tar.bz2

# cd httpd-2.2.4

参考INSTLL安装文档,如下即可安装apache(自带有cgi,perl, apxs的支持):

# ./configure --prefix=/usr/local/apache2 (不需要加--enable-so参数,

# make

# make install

3、安装Tomcat (解压即可)

# cp apache-tomcat-5.5.20.tar.gz /usr/local/

# cd /usr/local

# tar xzvf apache-tomcat-5.5.20.tar.gz

# ln -s apache-tomcat-5.5.20 tomcat

4、编译生成mod_jk

# tar xzvf tomcat-connectors-1.2.20-src.tar.gz

# cd tomcat-connectors-1.2.20-src/jk/native

# ./configure --with-apxs=/usr/local/apache2/bin/apxs

# make

# cp ./apache-2.0/mod_jk.so /usr/local/apache2/modules/

5、配置

在/usr/local/apache2/conf/下面建立两个配置文件mod_jk.conf和workers.properties。

# vi mod_jk.conf

添加以下内容:

# 指出mod_jk模块工作所需要的工作文件workers.properties的位置

JkWorkersFile /usr/local/apache2/conf/workers.properties

# Where to put jk logs

JkLogFile /usr/local/apache2/logs/mod_jk.log

# Set the jk log level [debug/error/info]

JkLogLevel info

# Select the log format

JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicate to send SSL KEY SIZE,

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format

JkRequestLogFormat "%w %V %T"

# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理

JkMount /servlet/* worker1

JkMount /*.jsp worker1

# vi workers.properties

添加以下内容:

# Defining a worker named worker1 and of type ajp13,

# 注意8009是tomcat的ajp13端口,注意不是8080

worker.list=worker1

# Set properties for worker1

worker.worker1.type=ajp13

worker.worker1.host=localhost

worker.worker1.port=8009

worker.worker1.lbfactor=50

#worker.worker1.cachesize=10

worker.worker1.cache_timeout=600

worker.worker1.socket_keepalive=1

worker.worker1.socket_timeout=300

6.再配置httpd.conf,作以下修改:

将Listen 80 修改为 Listen 127.0.0.1:80

将ServerName 修改为 ServerName localhost:80

在DirectoryIndex中添加 index.jsp, 假设网页放在/var/wwwroot下,要修改DocumentRoot

DocumentRoot "/var/wwwroot"

<Directory "/var/wwwroot">

Options Includes FollowSymLinks

AllowOverride None

Order deny,allow

Allow from all

XBitHack on

</Directory>

<Directory "/var/wwwroot/WEB-INF">

Order deny,allow

Deny from all

</Directory>

增加关于加载mod_jk的语句:

LoadModule jk_module modules/mod_jk.so

Include /usr/local/apache2/conf/mod_jk.conf

在/var/wwwroot下建立一个index.jsp,启动Apache和Tomcat,用浏览器访问http://localhost/,应可看到正确的页面。

---------------------------------------------------------------------------------------------------------------

II.tomcat, apache整合后,去掉tomcat的8080端口服务,用户只能通过80端口访问服务器 (以统一日志分析等的处理):

找到server.xml, 去掉port="8080"

<Connector port="8080" maxHttpHeaderSize="8192"

maxThreads="5000" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" redirectPort="8443" acceptCount="100"

connectionTimeout="20000" disableUploadTimeout="true"

URIEncoding="UTF-8" useBodyEncodingForURI="true" />

---------------------------------------------------------------------------------------------------------------

III.Tomcat/Apache乱码问题解决

首先,确保 httpd.conf中的下面一行的注释没有打开(未配置AddDefaultCharset ):

#AddDefaultCharset ISO-8859-1

然后依情况按步骤1), 2)操作

如果你的网页中定义的charset为UTF-8, 如下

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

那么步骤1-2用UTF-8替代GBK

1)如果你将apache和tomcat整合了,那么修改tomcat/conf中的server.xml

<Connector port="8009" enableLookups="false" redirectPort="8443" debug="0"

protocol="AJP/1.3" URIEncoding="GBK"/>

添加URIEncoding="GBK",请确保你的jsp的开头:

<%@page contentType="text/html;charset=GBK"%>

里的charset和URIEncoding一致。 (均为GBK或UTF-8)

2)如果没有将tomcat和apache整合,那么修改如下的标签:

<Connector

port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"

enableLookups="false" redirectPort="8443" acceptCount="100"

debug="0" connectionTimeout="20000"

disableUploadTimeout="true" URIEncoding="GBK"/>

参考:

http://www.gbunix.com/htmldata/2006_08/15/23/article_1383_1.html

http://dev.cbw.com/web/apache/2005524308_3480676.shtml

---------------------------------------------------------------------------------------------------------------

IV.虚拟主机配置:

删除掉下面这一行的#(取消注释)

#Include conf/extra/httpd-vhosts.conf

vi conf/extra/httpd-vhosts.conf, 根据文件中的例子添加虚拟主机。

参考:

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

http://httpd.apache.org/docs/2.2/vhosts/examples.html

hacking linux - find an unkown command for a desired function in a special linux distribution

If you use linux everyday, sometimes you post a problem on the newsgroup, someone would tell you a command called foobar would solve the problem. But when you type foobar in terminal, it shows "-bash: foobar: command not found", then you may wondering whether linux is as good as said, or whether your distribution is as good as others, or people had given a wrong answer. Stop wondering now,

I met the problem sometimes. and got the solution by "man -k command" .

Case 1: when i use ant files to build eclipse project, error occurred as "ant: /bin/sh^M: bad interpreter: No such file or directory." , which is described on the post:
Use eclipse with ant to deploy your java project -- from beginning of env setup to ant build .

I googled and find a post on apache mailing list, people suggest use unixdos to convert text file "ant" from dos format to unix format. I type unixdos, failed with "command not found". After thinking a while, I type :
$ man -k dos |grep -i unix
ExtUtils::MM_DOS (3) - DOS specific subclass of ExtUtils::MM_Unix
fromdos (1) - convert DOS text file format to UNIX
mcopy (1) - copy MSDOS files to/from Unix
mtools (1) - utilities to access DOS disks in Unix
todos (1) - convert UNIX text file format to DOS

Yes, fromdos, it is what i am finding. here i use man and grep to find the proper command.


Case 2: I need to convert GBK encoded text file to UTF-8 format. and googled around several times, couldn't get any useful info.

%man -k convert |grep -i encoding

the command could not find any useful command, thought it a lit while, hmmm, i need a command for character conversion

%man -k convert | grep -i character
...
%man -k conversion |grep -i character

fwprintf [wprintf] (3) - formatted wide character output conversion
iconv (3) - perform character set conversion
iconv_close (3) - deallocate descriptor for character set conversion
iconv_open (3) - allocate descriptor for character set conversion
...

Yes, iconv is exactly what i need.

Google is dangerous

Nowadays, excellent developers use google to help them solve problems or learn
new things. If you post an article on a newsgroup saying that you use yahoo
or baidu.com to hack a problem, someone would tell you "developers all use
google to solve problem".

Yes, it is true, google has been more 'n more important in our life, and it
does help, especially for developers. Sometimes, I spend a whole day or more
in googling a solution (it does has great help).

The problem is, when I use google more and more, someday I found that even I
need google to find some common knowledge. But I think these googled common
knowledge and other similar( ungoogled ) should be learned from books or an
official web site.

The keypoint is, there are lots of common knowledge, if I don't know these
things, even i don't kown what to google; Also when using google to learn a
new technology, it would cost much time than deserved when you know little
about the technology.

So if i use google more 'n more, i would be more 'n more lazy, impetuous.

The solution: to read more books, and learn from newgroups, some website.

SVN 项目管理使用FAQ

/******************* SVN 项目管理使用FAQ. **********************
* Author David Lv Euler
* Createddate 2007-2-1
* Contact david.ullua at gmail (please add .com to gmail)
* You can redistribute the total file wherever you like, but pls keep the
author's info. The document is provided WITHOUT any warranty.
****************************************************************/

1.如何将eclipse的项目添加到SVN管理:
a.对于建立好的项目(未受SVN管理),在eclipse中,右键点击项目名,点"ShareProject", 选"SVN",点"下一步"

b.选择"创建新的资源库位置",或者"使用已有的资源库位置",选择资源库后点"下一步",

c.假定选择或者创建的资源库位置为svn://172.16.100.26, 通常要选择服务器上特定的目录下面保存项目,
比如在svn://172.16.100.26/dev-source/app/下面,那么就选择"使用指定的模块名",
点浏览并选择:svn://172.16.100.26/dev-source/app/,
这个时候在输入框里面会有一个"New Folder"被选中, 把New Folder改为项目的名称。点"下一步"。

2.如何利用eclipse(已安装subclipse插件), 从SVN上取得项目到本地的Workspace中:
a. Eclipse 中点"File" -> "New" -> "other" , 选择SVN, "从SVN取出项目".

b. 选择"创建新的资源库位置",或者"使用已有的资源库位置",选择资源库后点"下一步"

c. 选择要导出的项目在SVN上的路径,比如dev-source/monternet/Server,
点"Next", 选择"做为新项目取出,
并使用新建项目向导进行配置", 点Finish. 这时会弹出New Project的向导,
因为项目在SVN上,本地上没有,所以会出现这个向导。

d. 在新建项目向导中,选择"Java" -> "Java Project"(比如ServerCore可能需要选择这个),
或者 "Web" -> "Dynamic Web Project" (比如LinuxWebSite项目可能需要选择这个).
点"Next", 输入Project name, 比如RobooProject. 点Next, 点"Finish"。
这样就完成了从SVN服务器上取出项目到Eclipse的workspace中

3. 为什么提交总是失败。
需要注意两点:
a.若与Tortoise 同时使用,那么尽量不要同时使用Tortoise和eclipse对一个目录进行操作。
b.在把其他目录的文件拷贝到受SVN管理的项目中时, 需要按目录提交,而不是按文件提交。
c.在对类名/文件名进行重构时,需要按目录(文件所在的目录)提交,而不是对单个的文件进行提交。

4.SVN客户端的常用命令有哪些?
如果装了Subversion, 在windows和linux下都可以用命令行来获取SVN上的信息。 有几个命令比较常用:
svn co
svn list
svn info
svn add
svn commit

比如
svn list svn://172.16.100.26/dev-doc/ , 显示服务器上指定目录的内容
svn co svn://172.16.100.26/dev-doc/ , 获取服务器上的内容
svn info svn://172.16.100.26/dev-doc/tools/subversion/svn_tutorial.txt , 显示SVN
上指定文件的信息。
svn info 显示当前受SVN 管理的目录信息。
svn add files_on_local_disk 添加本地文件到SVN 管理(此命令尚未将文件上传到SVN中)
svn commit (提交所做的改动, 上传用svn add 命令添加的文件)

5. 如何使用命令获取SVN的项目到eclipse中进行管理?
用命令获取项目, 再从eclipse打开项目会更方便。比如获取ServerCore项目, 我这样做:
1. svn co svn://172.16.100.26/dev-src/ServerCore(获取服务器上的项目到当前目录下,会产生RobooCore
目录)
2.从eclipse新建项目, 指定步骤1中获取到的项目目录. 这样就完成了从SVN获取项目到Eclipse.
比前面问题2中的a, b, c, d 四步要方便很多。

6. 为什么会遇到 Authentication Failed?
Authentication Failed通常是因为没有对应目录的权限所导致。

7. 为什么我遇到 Out of date: '/dev-src/xxx/yyy' in transaction '102-1'
当本机修改的文件不是服务器上的最新版本,修改本机文件后commit, 会提示out of date的错误。
需要先从服务器上获取最新版本(update), 然后进行修改,这时候再提交就可以了。

1/29/2007

Mysql starting error: ... STOPPING server from pid file /var/lib/mysql/roboo-lvzg.pid , mysqld ended

When I start mysqld server (in slackware linux 11), got error as follows:

root@kseeker-lvzg:~# mysqld_safe --user='mysql' &

[1] 10624

root@kseeker-lvzg:~# Starting mysqld daemon with databases from /var/lib/mysql

STOPPING server from pid file /var/lib/mysql/kseeker-lvzg.pid

070129 18:55:45 mysqld ended

oh, you need to su mysql and run mysql_install_db to fix the problem.

root@kseeker-lvzg:~# su mysql

mysql@kseeker-lvzg:/root$ mysql_install_db

Installing all prepared tables

Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server

to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h kseeker-lvzg password 'new-password'

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the 'sql-bench' directory:

cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

java knowledge tree

this java knowlege tree is composed and exported by FreeMind 0.8 (http://freemind.sourceforge.net) a little regret is the expand and collapse function is lost on the blog.





1/25/2007

利用~/.netrc文件自动ftp下载文件 (当天或昨天的tomcat日志)

home目录中添加文件.netrc,内容如下:

#download files begin with test under user david's home

machine 172.16.100.30 login david password 3287

macdef init

binary

prompt

!clear

mget test*

!clear

bye


#get the log of yesterday:

#echo "catalina.`date --date='1 days ago' +%Y-%m-%d `.log" | ftp www.kseeker.com

#download file specified by the second arg (the log filename)

machine www.kseeker.com login david password pass92342@#$@**(89

macdef init

binary

prompt

cd /home/tomcat/logs

mget $2

bye


注意:bye后要有一空行,.netrc文件的属性须是600,

可以使用这个命令下载172.16.100.30上面/home/david/目录test开头的文件:%ftp 172.16.100.30


可以使用这个命令来下载服务器上昨天的tomcat日志(文件名如: catalina.2007-01-24.log):

%echo "catalina.`date --date='1 days ago' +%Y-%m-%d `.log" | ftp www.kseeker.com

man netrc, 可以看到更多信息:

NETRC(5) BSD File Formats Manual NETRC(5)

NAME

netrc, .netrc -- user configuration for ftp

DESCRIPTION

This file contains configuration and autologin information for the File Transfer Protocol client ftp(1).

The .netrc file contains login and initialization information used by the auto-login process. It resides in the user's

home directory. The following tokens are recognized; they may be separated by spaces, tabs, or new-lines:

......

1/22/2007

KMail提示用户可能忘了附件的有趣功能

今天发邮件的时候,KMail居然提示我"可能有附件,要不要附加文件,还是原样发送?"
原来我的邮件的内容中含有attachment这个单词, 新建一封邮件, 里面有"附件"这个词,发送的时候KMail也提示是否要附加附件。
看起来KMail会自动检测邮件中是否有attachment,或者"附件"的单词存在,存在的时候,如果没有附加附件,在发送时会提醒是否附加附件。

这项功能实在蛮有趣的,开发者考虑的还真周到,象我这种粗心的人,曾饱受outlook发送邮件忘记附件之苦, 用KMail问题都解决了。

use crontab and mail command to backup your firefox bookmarks

add the following line to ~/cron.yourname , (yourname is your real login name)

30 12 * * * date '+%m/%d/%Y' | mail -s "bookmark"" `date '+%m/%d/%y'`" -a /home/yourname/.mozilla/firefox/68k8bqg9.default/bookmarks.html receiver1@abc.com receiver2@abc.com

maybe 68k8bqg9.default should be replaced by your actual bookmarks directory.

and run:

%crontab ~/cron.yourname

then crontab would run at 12:30 am to send firefox bookmark to your email receiver1 and receiver2.

date '+%m/%d/%Y' : to show date as "01/23/2007"

it use filter to current date as the mail's content. and use -a to specify the attachment.

it use -s spesify subject as: "bookmark"" `date '+%m/%d/%y'`" ,

here date is backquoted.

send mail with attachment in command line

if it is a normal text file, you can use redirection to send the file as
content:

mail -s "hello, david" someone@abc.com someone2@kseeker.com < attachfile

if it is a binary file, or you want to send text file as real attachment:

mail -s "hello, david" -a attachfile someone@abc.com someone2@kseeker.com

btw, mail is often the alias of mailx command in linux.

1/15/2007

add authentication for awstats in apache

awstats does not require an authentication by default.
but we can use apache's auth_module to add authentication for a specified directory( in this case is awstats).

assume awstats config file is /etc/awstats/awstats.kseeker.com.conf ,
awstats is installed at /usr/local/awstats/, awstats.pl is located at /usr/local/awstats/wwwroot/cgi-bin.
and httpd.conf is located at /etc/httpd/conf/.

step 1: config awstats to enable authentication access
%vi /etc/awstats/awstats.kseeker.com.conf, find the line contains AllowAccessFromWebToAuthenticatedUsersOnly, and the line contains
AllowAccessFromWebToFollowingAuthenticatedUsers, change them as follows:
AllowAccessFromWebToAuthenticatedUsersOnly=1
AllowAccessFromWebToFollowingAuthenticatedUsers="david"

step 2: enable apache authentication for awstats directory
%vi /etc/httpd/conf/httpd.conf, set AllowOverride to All for "/usr/local/awstats/wwwroot/cgi-bin" directory:

<Directory "/usr/local/awstats/wwwroot/cgi-bin">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>

step 3: add authentication file and .htacess file, add user , and restart apache

%cd /usr/local/awstats/wwwroot/cgi-bin
%htpasswd -c userfile david //create user file, it will prompt for user's password.
%cat > .htaccess
AuthUserFile /usr/local/awstats/wwwroot/cgi-bin/userfile
AuthName "Restricted Area For Customers"
AuthType Basic
require valid-user
Ctrl + D

% apachectl restart

vim与gvim 转换highlight的文本到html网页

今天发现用gvim居然可以把vim中着色显示的文本文件(c, php, sh, java, ...)转换成html,
且保留显示的格式和颜色,不必再为发布源代码到blog上显示格式混乱的问题了。

在gvim中点syntax => convert to html, 这样会产生一个后缀名加上html的文件,
然后保存即可(:w ).如果要对.html文件或者源文件作适当的编辑,
可以用Ctrl+ww 可以切换源文件与产生的html文件的窗口。

google 了一下"vim convert to html", 原来vim中也可以使用

:runtime! syntax/2html.vim 命令来保存按语法高亮显示的文本到html文件。

参考: http://vimdoc.sourceforge.net/vimfaq.html

24.14. How do I convert a source file (.c, .h, etc) with the Vim syntax
highlighting into a HTML file?

You can use the 2html.vim script to convert a source file into a HTML file

with the Vim syntax highlighting. Use the following command:
:runtime! syntax/2html.vim

For more information, read

:help convert-to-HTML

1/12/2007

Use eclipse with ant to deploy your java project -- from beginning of env setup to ant build

1.export project to ant build file.
2.run junit testing default build file
3.make your own build file,add unit test and junitreport to build.
4.create target of : makepackage,deployapp
5.run ant under linux terminal or win command line, or add it to scheduled tasks.
Q1: "Ant-junit, build failed: Could not create task or type of type: junit"
Q2: "ant: /bin/sh^M: bad interpreter: No such file or directory."

This tutorial shows how to use ant within eclipse to build, test, make package and deploy your app using eclipse step by step. Any questions, please feel free to contact me at david.ullua at gmail, or leave a comment. The tutorial is tested under eclipse 3.1.2, ant 1.6.5. in other higher version in the future should also works. The tutorial is oriented for readers without any knowledge about make,ant or similar build tools, while also can be as a reference for middle experienced developer.

1. export project to ant build file.
Open your java project in eclipse,select your project, right click mouse, click "export", choose "General" => "Ant BuildFiles", click "Finish", it will generate a build.xml file. The default build file includes project build target and junitreport target. we can use the default build.xml as a start.

Open build.xml, here is the first line( space after > is added for web display ) :
< basedir="." default="build" name="twoway-analyzer">< /project>
It mean the build file would take project path as basedir, and use build target as default task when running "ant" or "ant -f build.xml" in project dir without args specifying target(s).

Look at this line in build.xml:
< depends="build-subprojects,build-project" name="build">
the line means build task depends on 2 sub-tasks, and does not contain any other independent actions in the build project. that's to say, if we run "ant -f build.xml", or "ant build", it will call 2 sub-tasks: build-subprojects, build-project.

ok, now you can right click "build.xml" => "Run As" => "Ant Build" (choose the one which you can select task else it would build default tasks) , then choose targets to excute, click "run", it will run the build task.

If you met the error of "Could not create task or type of type: junit", see Q1 in the end of this article as reference.


2. run junit testing default build file
the default build file contains tests and junitreport,
you can merge seperate unit tests to one target as follows,
it combines all 4 unit tests into one target called unitTest:

<target name="unitTest">
<mkdir dir="${junit.output.dir}"/>
    <junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="com.roboo.segmenter.unitTest.DictionaryTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.MMTokenizerTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.OriginTokenizerTest" todir="${junit.output.dir}"/>
<test name="com.roboo.segmenter.unitTest.RMMTokenizerTest" todir="${junit.output.dir}"/>
<classpath refid="twoway-analyzer.classpath"/>

target>
now in eclipse you can choose unitTest to run all tests.
and you can choose junitreport, this time the report would be generated. Attention if you have chosen junitreport before unitTest, then need to adjust targets order to make sure that unitTest is done before junitreport. else the report would be generated by old data.


3.make your own build file,add unit test and junitreport to build.

every time when you export Ant Buildfiles, the default build.xml will be override. so just make your own build file. save build.xml to custbuild.xml. Also we want ant run not only as eclipse plugin but also in terminal by a single command, ok, we can add these targets to the depends of build target. find this line in custbuild.xml(which we copied from build.xml):

<target depends="build-subprojects,build-project" name="build"/>

change it to :
<target depends="build-subprojects,build-project,unitTest,junitreport" name="build"/>

now can run "ant -f custbuild.xml" in command line to run project build,unitTest and junitreport in 1 step.

when running ant, if you met the error of "ant: /bin/sh^M: bad interpreter: No such file or directory.", see Q2 as reference in the end of this article.


4.create target of : makepackage,deployapp
now we want to make a jar package for the project, then add the following target:

-- jar task to make package -->
<target name="makepackage">
< echo message="Making jar package ....."/>
< delete file="${package.name}${package.version}.jar" />
< jar destfile="${package.name}${package.version}.jar"basedir="bin" excludes="*.*,**/allwords.dict" update="false">
-- exclude normal files under bin directory -->


don't forget to add the target name to the depends for "build" target.
here package.name and package.version is predefined in the properties of the build file(after xml file's root element):
<property name="package.name" value="roboosegmenter"/>
<property name="package.version" value="1.3.2.0"/>

after making the jar package, we need to deploy it to web apps.
here app_lib_dir,tomcat_web_lib_dir is predefined in the properties of the build file(after xml file's root element)
 -- deploy segmenter lib to app_lib_dir and tomcat_web_lib -->
<target name="deployapp">
<delete>
<fileset dir="${app_lib_dir}" includes="${package.name}*jar"/> < /delete>

<copy file="${package.name}${package.version}.jar" todir="${app_lib_dir}"/>

<delete>
<fileset dir="${tomcat_web_lib_dir}" includes="${package.name}*.jar"/> < /delete

<copy file="${package.name}${package.version}.jar" todir="${tomcat_web_lib_dir}"/>
don't forget to add the deployapp target to your build define, like this:
<target depends="build-subprojects,build-project,unitTest,junitreport,makepackage,deployapp"name="build"/>


5.run ant under linux terminal or windows command line, or add it to scheduled tasks.

to build project, run unit test, make jar package and deploy app:
%ant -f custbuild.xml

to build project do not run unit test or deploy:
%ant -f custbuild.xml unitTest

to build project and run just unitTest without deploy:
%ant -f custbuild.xml build-project unittest


Q1: Ant - junit, build failed: Could not create task or type of type: junit

When running JUnit tasks in ant and you get the following error:

BUILD FAILED
path\to\...\build.xml:259: Could not create task or type of type: junit.
Ant could not find the task or a class this task relies upon.

To fix this problem, you need to copy a JUnit.jar file to your eclipse/plugins/org.apache.ant_1.65/lib directory,
Go into Eclipse then click on Window->Preferences->ant->Runtime,
select 'Ant Home Entries (Default). Click on the button 'Add External JARs'. Locate the junit.jar file you copied, select it and hit 'OK'. Hit 'Apply', then 'OK' and try your ant task again. That should fix it.


Q2:when i run ant in unix/linux terminal it shows the following error: eclipse/plugins/org.apache.ant_1.6.5/bin/ant: /bin/sh^M: bad interpreter: No such file or directory.
A2:caused by file format under dos/windows is different to unix ,
%fromdos <> file2 or use dos2unix to change the file format.

1/11/2007

Eclipse and gaim font settings under KDE

When I opened gaim under KDE, the menus and dialogs are very ugly. And I have use eclipse day by day under KDE about 2 months. The dialog and menu, and editor fonts are fairly ugly for both English and Chinese. So I decide to change these fonts.

In eclipse Windows -> Preferences, -> General -> Appearance -> Color and Fonts, type "font" as filter , all fonts settings would be shown, dialog font, text editor font, java editor font, console fonts, etc. I change all fonts to WenQuanYi BitMap Song which support Chinese perfectly.

However in eclipse settings it's own menu font cannot be changed. after googled "elipse menu font" and "eclipse 菜单字体", found the solution:
download and install gtk-qt-engine here .

Then under the KDE Control-Center -> Appearence && Themes (外观和主题) , a submenu called "GTK Styles and Fonts" would be available, you can change the gtk Fonts here.

Now gaim also look fine.


The eclipse and gaim font problem's root cause is that :
1.Eclipse use SWT to show its UI; SWT is implemented by windows/gtk/motif
2.Running Eclipse on linux/gtk, need gtk libraries.
3.KDE is based on QT not GTK, so it need gtk-qt-engine to config GTK Style and Fonts. gtk-qt-engine is used to do it.

to implement SVN password changing function by shell and php

We have install SVN as our version control system. It doesn't provide a remote password changing function on the web. I googled on the internet and didn't found a good solution. So I wrote a script in bash and a php front end page to do it.
(if you need a jsp or perl front end page, you can write one yourself)

Here's the shell script to change password for svn:

#!/bin/sh
#changepass.sh , function: change password for svn
#usage: changepass.sh username oldpass newpass newpassretype
if [ ! "$#" = 4 ]
then
echo "Usage:`basename $0` username oldpass newpass newpassretype"
exit 1
fi

passfile="/home/svn/passwd"

username=
oldpass=
newpass1=
newpass2=

username=$1
oldpass=$2
newpass1=$3
newpass2=$4

if [ ! $newpass1 = $newpass2 ]
then
#echo "password does not match!";
echo "password does not match!"
exit 2
fi

export NEWPASS=$newpass1
export USERNAME=$username

i=`sed /^"$username"[" ""\t"]*=[" ""\t"]*$oldpass\$/p $passfile -n|wc -l`
if [ $i = 1 ]
then
awk '{ if(index($0,ENVIRON["USERNAME"])==1) {print ENVIRON["USERNAME"] " = " ENVIRON["NEWPASS"] }else {print $0} }' $passfile > /home/svn/newpass

rm /home/svn/newpass 2>&1 1> /dev/null
cp /home/svn/newpass $passfile

echo 'password changed!'
elif [ `sed /"$username"/p $passfile -n |wc -l` > 0 ]
then
echo ' username and password does not match'
else
echo 'could not find username'
fi


here's the php front end changepass.php , it is for php 5, if you use php 4, maybe you need use $HTTP_POST_VARS instead $_POST ( just guess, i haven't test it):



if(strlen($_POST["pwd1"]) >0 ){
if($_POST["pwd1"]!=$_POST["pwd2"]){
print("Passwords do not match, try again.

\n");


}else{

$LoginName = $_POST["loginname"];
$OldPassword = $_POST["oldpwd"];
$NewPass1 = $_POST["pwd1"];
$NewPass2 = $_POST["pwd2"];
$retval='';
#echo $LoginName;
#echo $OldPassword;
// user apache or nobody(who runs httpd daemon) needs the permission of passwd file and temp file
$command = "/mnt/apache/changepass.sh ".$LoginName." ".$OldPassword." ".$NewPass1." ".$NewPass2 ;

#$command = "/bin/cat /mnt/apache/changepass.sh "." 2>&1";
$command = $command." 2>&1";

#system("/bin/echo abc",$retval);
system($command, $retval);

echo "
" ;echo $retval;echo '
';


if($retval!=0){
print("
Error while setting password:
\n");

}

}
}
else{
;#echo "parameters not set!";
}
?>





Login Name:
Old Password:
New Password:
Repeat Password:


the php page and shell scripts should works ok, but the php page shows nothing after click "submit" in fedora, however in slackware it is ok.

After debug step by step, found that shell script error message would not be ouput on the web page, so i add this line: $command = $command." 2>&1";

And finally found that SELinux would block some function on the web server. I disabled SELinux in the firewall settings, and it works.



difference on class between php version 4.4.4 and 5.2.0

Different PHP versions behalves differently. The only two distribution on php.net is 4.4.4 and 5.2.0. The experience of the article describes class difference between 4.4.4 and 5.2.0 is that:
1). class members variable is decorated by "private" in 5.2.0, as "var" in 4.4.4
2). class functions is decorated by "public function" in 5.2.0, as "function" in 4.4.4


Several days ago, i wrote a php proxy for wap.roboo.com to transfer jsp response to a php server. And grabed a HTTPRequest class from google, the class code is as follows:

class HTTPRequest
{
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port

// scan url
function _scan_url()
{
....
}

// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}

// download URL to string
function DownloadToString()
{
....
}
}

I use Slackware 11 to do most works, slack use php 4.4.4 by default. the HTTPRequest works ok on my machine. After deploy it on another fedora machine which has php 5.0 by default, it fails. Then I updated it to php 5.2.2, with the help of one colleague, I changed the class as follows to support 5.2.2:

class HTTPRequest
{
private $_fp; // HTTP socket
private $_url; // full URL
private $_host; // HTTP host
private $_protocol; // protocol (HTTP/HTTPS)
private $_uri; // request URI
private $_port; // port

// scan url
public function _scan_url()
{
....
}

// constructor
public function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}

// download URL to string
public function DownloadToString()
{
....
}
}

By the way, i use vi(vim actually) to edit source, just use :0,$s/var/private/g , :0,$s/function/public function/g to do the substitution.

After disabled SELinux on fedora , it works ok.

About Me

I am a senior developer and a team leader with 3 years development experience in Suzhou, China, focus on mobile web search, linux, Java and machine learning in NLP (natural language processing). My goal is to improve people's life with computer technology.