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

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

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.

2/04/2007

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/

1/29/2007

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/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.

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.