build scripts
DESCRIPTION
Sutt kynning á "Build scripts" með ANTTRANSCRIPT
Build Scripts
Reading: Ant article
Why Build Scripts?
§ For large enterprise systems using the IDE is not sufficient for building § Complicated Builds § Automatic Nightly Builds § Special Build Machines
§ Important to be able to separate build and development
What is Ant?
§ ANT is a tool to build programs § “make” tool § Uses XML file to describe the solution § Default file is build.xml
§ Uses Java classes to run tasks § Built-in tasks
§ Jakarta project § http://ant.apache.org § Current version 1.8.2
§ Installation guidelines are on the course web
Ant in use
Verkefni>
Verkefni build.xml src/
Verkefni>ant Buildfile: build.xml ...
Project build.xml src/ classes/ dist/
ANT file Source
Class files JAR file
Project>ant Buildfile: build.xml ... BUILD SUCCESSFUL Total time: 4 seconds
Command Prompt
Running Ant
§ Usage ant [options] [target [target2 [target3] ...]]
§ Target can be selected § Default is used if target is not specifed
§ Examples >ant -buildfile test.xml
>ant -buildfile test.xml dist
>ant -buildfile test.xml -Dbuild=build/classes dist
Using Ant
§ Each build file is one project (one output) § Build file is XML file (for example build.xml)
§ Project has § Name § Default target § Basedir § One or more target
§ Target § Target is a collection of tasks § Task depend on
other tasks <target name="A"/> <target name="B" depends="A"/> <target name="C" depends="B"/> <target name="D" depends="C,B,A"/>
<project name="MyProject" default="dist" basedir="."> ... </project>
Using Ant
§ Properties § Have names and values
§ Referenced with ${property} § Example:
<property name="dist" value="dist"/>
<target name="dist" depends="compile"> <mkdir dir="${dist}/lib"/> <jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </target>
Example build.xml file
Import Contents Process
Structure
§ Work space § build.xml § src/java – contains the Java files § src/msg – contains resource bundles § lib/ - contains libraries (jar files)
§ Ant made directories § classes/ - compiled Java files – class files § dist/ - distributable - jar files
§ JAR file § dist/ImportContentProcess.jar
build.xml <project name="ImportContentProcess" default="jar" basedir="."> <property name="src.java" value="src/java"/> <property name="src.msg" value="src/msg"/> <property name="output.dir" value="classes"/> <property name="dist.dir" value="dist"/> <property name="lib.dir" value="lib"/> <property name="jar.file" value="ImportContentProcess.jar"/> <property name="classpath" value="${lib.dir}/rome-0.8.jar:${lib.dir}/jdom.jar:${lib.dir}/spring.jar:${lib.dir}/commons-logging.jar:${lib.dir}/ruframework.jar"/> <target name="init" description="Prepare by creating output directories"> <mkdir dir="${output.dir}"/> <mkdir dir="${dist.dir}"/> </target>
build.xml <target name="compile" depends="init" description="Compilation of all source files"> <javac srcdir="${src.java}" destdir="${output.dir}" classpath="${classpath}"/> </target> <target name="jar" depends="compile" description="Create the JAR"> <jar jarfile="${dist.dir}/${jar.file}" basedir="${output.dir}"> <fileset dir="${src.msg}"/> </jar> </target> <target name="clean" description="Delete all generated files"> <delete dir="${output.dir}"/> <delete dir="${dist.dir}"/> </target> </project>
Building C:\hr\Honn>ant Buildfile: build.xml init: [mkdir] Created dir: C:\hr\Honn\classes compile: [javac] Compiling 11 source files to C:\hr\Honn\classes jar: [jar] Building jar: C:\hr\Honn\dist\ImportContentProcess.jar BUILD SUCCESSFUL Total time: 2 seconds C:\hr\Honn\>java -cp lib\commons-logging.jar;lib\jdom.jar;lib\rome-0.8.jar;lib\ruf ramework.jar;lib\spring.jar;dist\ImportContentProcess.jar is.ruframework.process.RuProcessRunner
Using Ant with IntelliJ
§ Most IDEs support ANT § Must use the same
folders § IntelliJ has ANT support
§ Easy to use § Ant is powerful when
using IntelliJ to develop container-based programs § For example EJBs, Web
Apps