build scripts

14
Build Scripts Reading: Ant article

Upload: olafur-andri-ragnarsson

Post on 29-Nov-2014

119 views

Category:

Software


3 download

DESCRIPTION

Sutt kynning á "Build scripts" með ANT

TRANSCRIPT

Page 1: Build Scripts

Build Scripts

Reading: Ant article

Page 2: Build Scripts

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

Page 3: Build Scripts
Page 4: Build Scripts

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

Page 5: Build Scripts

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

Page 6: Build Scripts

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

Page 7: Build Scripts

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>

Page 8: Build Scripts

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>

Page 9: Build Scripts

Example build.xml file

Import Contents Process

Page 10: Build Scripts

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

Page 11: Build Scripts

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>

Page 12: Build Scripts

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>

Page 13: Build Scripts

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

Page 14: Build Scripts

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