注意:我们知道Jenkins通过master/slave来支持分布式的job运行,这里的JavaHelloworld运行在master,即Jenkins所在的机器。
一 Java的HelloWorld程序
Ant构建脚本:c:\JavaHelloWorld\build.xml
<
project
name
="HelloWorld"
basedir
="."
default
="main"
>
<
property
name
="src.dir"
value
="src"
/>
<
property
name
="build.dir"
value
="build"
/>
<
property
name
="classes.dir"
value
="${build.dir}/classes"
/>
<
property
name
="jar.dir"
value
="${build.dir}/jar"
/>
<
property
name
="main-class"
value
="oata.HelloWorld"
/>
<
target
name
="clean"
>
<
delete
dir
="${build.dir}"
/>
</
target
>
<
target
name
="compile"
>
<
mkdir
dir
="${classes.dir}"
/>
<
javac
srcdir
="${src.dir}"
destdir
="${classes.dir}"
/>
</
target
>
<
target
name
="jar"
depends
="compile"
>
<
mkdir
dir
="${jar.dir}"
/>
<
jar
destfile
="${jar.dir}/${ant.project.name}.jar"
basedir
="${classes.dir}"
>
<
manifest
>
<
attribute
name
="Main-Class"
value
="${main-class}"
/>
</
manifest
>
</
jar
>
</
target
>
<
target
name
="run"
depends
="jar"
>
<
java
jar
="${jar.dir}/${ant.project.name}.jar"
fork
="true"
/>
</
target
>
<
target
name
="clean-build"
depends
="clean,jar"
/>
<
target
name
="main"
depends
="clean,run"
/>
</
project
>
Java的helloworld: c:\JavaHelloWorld\src\oata\helloworld.java
package oata;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
二 启动Jenkins且创建job来运行JavaHelloWorld
1) 启动jenkins在8000端口:
2) 创建JavaHelloWorld的job
在ie中打开http://localhost:8000,
单击new job链接,为javahelloworld新建job,且编译job的配置如下:
注意jenkins默认已经安装了svn的plugin了。
3) 运行JavaHelloWorld的job
进入JavaHelloWorld的主页面,点击build now链接进行build,build后可以在此主页面上看到所有的build历史,如下:
然后还可以点击某个build的链接,查看某个build的详细日志,如下:
参考:
http://ant.apache.org/manual/tutorial-HelloWorldWithAnt.html