In previous post, I have mentioned the way to run a Java program as a windows service. I like the wrapper tool kit from Tanuki Software very much. However, I encounter some inconvenient situation during the deploy process. For example, the classes build by the IDE have to become a jar file and deploy to the wrapper environment's library folder. It really troublesome when debuging the program. Basically, this is a typical build process problem. Hence, the build tool can tackle this probelm very easily. In Java world, the Apache Ant is the De facto standard of build process execution tool. I develop a small build script to deal with this problem.
Step 1.
Revise the development folder structure.
MYProject
+bin
+wrapperTemplate (download it from Tanuki Software)
+dist
+build
+src
Step 2.
Construct the build script.
<project name="Build&DeployJavaWrapperAp" default="deploy">
<property name="wrapper.dir" location="wrapperTemplate"/>
<mkdir dir="bin"/>
<path id="compile.classpath">
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<mkdir dir="build/classes"/>
<mkdir dir="dist"/>
</target>
<target name="compile" depends="init">
<javac srcdir="./src" destdir="build/classes">
<classpath refid="compile.classpath"/>
</javac>
<jar destfile="dist/myproject.jar" basedir="build/classes"/>
<echo>Compilation complete</echo>
</target>
<target name="deploy" depends="compile">
<copy todir="bin">
<fileset dir="${wrapper.dir}"/>
</copy>
<copy todir="bin/${wrapper.dir}/lib">
<fileset dir="dist"/>
</copy>
</target>
<target name="clean" depends="init"/>
</project>
Step 3.
Execute the script.
Just in the Dos command prompt,
in the root folder of the project.
Type: ant (press enter).
This build script help me a lot and I wish this post also can benefit you.
2008年8月7日 星期四
Ant Build File for Windows Service Wrapper
標籤:
Ant,
Build Process,
Java
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言