How to put comment in Ant | Comments in Apache Ant

comments-in-apache-ant

How to put comment in Ant | Comments in Apache Ant

Method 1:

<!– Comments are just as important in buildfiles, do not –>
<!– avoid writing them! –>
<!– Example build file for “Ant: The Definitive Guide” –>
<!– and its sample project: irssibot –>

Method 2: Echo
Description
Writes a message to the Ant logging facilities. A message may be supplied
as nested text to this task.
Echoes a message to the current loggers and listeners which means System.out unless overridden. A level can be specified, which controls at what logging level the message is filtered at.
The task can also echo to a file, in which case the option to append rather than overwrite the file is available, and the level option is ignored

Parameters

Attribute Description

Required

message the message to echo.

No. Text may also be included in a character section within this element. If neither is included a blank line will be emitted in the output.

file the file to write the message to.

No

append Append to an existing file (or open a new file / overwrite an existing file)?

No – default is false.

level Control the level at which this message is reported. One of “error”, “warning”, “info”, “verbose”, “debug” (decreasing order)

No – default is “warning”.

encoding encoding to use, default is “”; the local system encoding. since Ant 1.7

No

Examples
Style 1:
<echo message=”Hello, world”/>

Style 2:
<echo message=”Embed a line break:${line.separator}”/>

Style 3:
<echo>Embed another:${line.separator}</echo>

Style 4:
<echo>This is a longer message stretching over
two lines.
</echo>

Style 5:
<echo>
This is a longer message stretching over
three lines; the first line is a blank
</echo>

Style 5:
<echo message=”Deleting drive C:” level=”debug”/>
A message which only appears in -debug mode.

Style 6:
<echo level=”error”>
Imminent failure in the antimatter containment facility.
Please withdraw to safe location at least 50km away.
</echo>
A message which appears even in -quiet mode.

Style 7:
<echo file=”runner.csh” append=”false”>#\!/bin/tcsh
java-1.3.1 -mx1024m ${project.entrypoint} $$*
</echo>
Generate a shell script by echoing to a file. Note the use of a double $ symbol to stop Ant filtering out the single $ during variable expansion
Depending on the loglevel Ant runs, messages are print out or silently ignored:

Ant-Statement

-quiet, -q

no statement

-verbose, -v

-debug, -d

<echo message=”This is error message.” level=”error” />

ok

ok

ok

ok

<echo message=”This is warning message.” />

ok

ok

ok

ok

<echo message=”This is warning message.” level=”warning” />

ok

ok

ok

ok

<echo message=”This is info message.” level=”info” />

not logged

ok

ok

ok

<echo message=”This is verbose message.” level=”verbose” />

not logged

not logged

ok

ok

<echo message=”This is debug message.” level=”debug” />

not logged

not logged

not logged

ok

Method 3:
Description

Tagged : / / / / / / / / / / / / /

How to run ant build in intellij? – IntelliJ/Ant integration Guide

intellij-ant-integration

IntelliJ/Ant integration
By Alvin J. Alexander, devdaily.com
The fact that IntelliJ is off-the-shelf ready to work with Ant is a great, great feature. It’s also simple to configure and use.
Assuming that you already know how to use Ant, and you have a build.xml file ready to go, just follow these steps to (a) configure your build script to run from within IntelliJ, and (b) run Ant:

  • Assuming you’re in an IntelliJ project, select 6: Ant Build from the slide-in menu bar (“Tool Window Bar”) on the right side of your screen.
  • Click the large plus sign icon to add your build.xml file to IntelliJ’s list of known build scripts for this project.
  • Navigate the filesystem until you find your build script (i.e., your build.xml file for this project). Select that file.
  • To run a desired Ant task, double-click the task name that you want to run. My main task is usually named deploy, so I double-click that.
  • Ant should run properly for you, and deploy your application.

It’s really that simple.
The worst problem I’ve run into so far is that when I work on projects on multiple computer systems, my build scripts rely on an environment parameter named ANT_HOST_NAME existing. So, when my build script failed the first time, I said “Oh, dummy Al, you need to set your ANT_HOST_NAME environment parameter. Once I did this and restarted IntelliJ, the Ant build process worked like a champ.
Kudos, dear IntelliJ developers. Great product feature!

Best Example of <Copy>
Type 1:
<copy todir=”${Temp}/uaw/Uaw_compilescripts” overwrite=”true” failonerror=”false”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts” includes=”BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script” />
</copy>

Type 2:
<copy todir=”${Temp}/uaw/Uaw_compilescripts” overwrite=”true” failonerror=”false”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts” includes=”BuildSh,Compsh,vsamc,buildc.sh,script,compl2,main.sh,makefile,makepl1,script” />
</copy>

Type 3:
<copy todir=”${Temp}/uaw/Uaw_compilescripts” overwrite=”true” failonerror=”false”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts”>
<include name=”BuildSh”/>
<include name=”Compsh”/>
<include name=”vsamc”/>
</fileset>

</copy>

Type4:
<copy todir=”${Temp}/uaw/Uaw_compilescripts” overwrite=”true” failonerror=”false”>
<fileset dir=”${SVNCheckout}/scripts/compilescripts”>
<includesfile name=”${List}/Uaw_compilescripts_list.txt”/>
</fileset>
</copy>

 

Tagged : / / / / / / / / / /

A sample Ant build script that builds a WAR file – Guide

ant-build-script-war-file

A sample Ant build script that builds a WAR file

<project name=”MyWebApplication” basedir=”..” default=”install”>

<!– project-specific variables –>
<property name=”jsp.dir.name” value=”myapp” />
<property name=”package.name” value=”${jsp.dir.name}.war” />
<property name=”webapp.dir” value=”/Users/al/tomcat-6.0.16/webapps” />

<property environment=”env” />
<property name=”build.dir” value=”build” />
<property file=”${build.dir}/build.${env.HOSTNAME}” />

<property name=”lib.dir” value=”lib” />
<property name=”pages.dir” value=”pages” />
<property name=”src.dir” value=”src” />
<property name=”src.tests.dir” value=”src-tests” />
<property name=”resources.dir” value=”resources” />
<property name=”dest.dir” value=”target” />

<!– put everything in a temp folder with the right structure during the build –>
<property name=”temp.dir” value=”temp” />
<property name=”temp.dir.web-inf” value=”${temp.dir}/WEB-INF” />
<property name=”temp.dir.lib” value=”${temp.dir.web-inf}/lib” />
<property name=”temp.dir.classes” value=”${temp.dir.web-inf}/classes” />
<property name=”temp.dir.meta-inf” value=”${temp.dir}/META-INF” />

<property name=”package.file” value=”${dest.dir}/${package.name}” />

<path id=”build.class.path”>
<fileset dir=”lib”>
<include name=”**/*.jar” />
</fileset>
</path>

<target name=”clean”>
<delete>
<fileset dir=”${dest.dir}” includes=”**/*”/>
</delete>
<delete dir=”${temp.dir}” />
<delete dir=”${temp.dir.classes}” />
<delete dir=”${temp.dir.meta-inf}” />
<delete dir=”${temp.dir.web-inf}” />
</target>

<target name=”prepare” depends=”clean”>
<mkdir dir=”${dest.dir}” />
<mkdir dir=”${temp.dir}” />
<mkdir dir=”${temp.dir.lib}” />
<mkdir dir=”${temp.dir.meta-inf}” />
<mkdir dir=”${temp.dir.web-inf}” />
<mkdir dir=”${temp.dir.classes}” />
</target>

<!– COMPILE –>
<target name=”compile” depends=”prepare”>
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files …</echo>
<javac debug=”on” srcdir=”${src.dir}” destdir=”${temp.dir.classes}” includes=”**/*”>
<classpath refid=”build.class.path” />
</javac>

<!– compile files on the src-tests path –>
<echo>Compiling ${src.tests.dir} files …</echo>
<javac debug=”on” srcdir=”${src.tests.dir}” destdir=”${temp.dir.classes}” includes=”com/**”>
<classpath refid=”build.class.path” />
</javac>
</target>

<!– PACKAGE –>
<target name=”package” depends=”compile”>
<echo>=== PACKAGE ===</echo>

<!– copy the config files –>
<copy file=”${resources.dir}/MANIFEST.MF” tofile=”${temp.dir.meta-inf}/MANIFEST.MF” overwrite=”true” />
<copy file=”${resources.dir}/web.xml” tofile=”${temp.dir.web-inf}/web.xml” overwrite=”true” />
<copy file=”${resources.dir}/managed-beans.xml” tofile=”${temp.dir.web-inf}/managed-beans.xml” overwrite=”true” />
<copy file=”${resources.dir}/navigation-rules.xml” tofile=”${temp.dir.web-inf}/navigation-rules.xml” overwrite=”true” />

<copy todir=”${temp.dir.classes}”>
<fileset dir=”${src.dir}”>
<include name=”**/*.xml”/>
<include name=”**/*.xsl”/>
</fileset>
</copy>

<!– with all resources in place, create the war file –>
<war destfile=”${package.file}” webxml=”${temp.dir.web-inf}/web.xml” basedir=”${temp.dir}”>
<fileset dir=”${pages.dir}”/>
<lib dir=”${lib.dir}” />
<classes dir=”${temp.dir.classes}” />
</war>
</target>

<!– JUST DEPLOY JSP’s –>
<target name=”jsps”>
<echo>=== DEPLOY JSP’S ===</echo>
<!– i’m trying to be explicit about what i put out there –>
<copy todir=”${webapp.dir}/${jsp.dir.name}”>
<fileset dir=”${pages.dir}”>
<include name=”**/*.jsp”/>
<include name=”**/*.html”/>
<include name=”**/*.css”/>
<include name=”**/*.gif”/>
<include name=”**/*.jpg”/>
<include name=”**/*.png”/>
<include name=”**/*.js”/>
</fileset>
</copy>
</target>

<!– INSTALL –>
<target name=”install” depends=”package”>
<echo>=== INSTALL ===</echo>
<copy file=”${package.file}” tofile=”${webapp.dir}/${package.name}” overwrite=”true” />
</target>

</project>

Tagged : / / / / / / / / / / / / / / / / /

Simple Ant Example – clean, prepare, and compile tasks

ant-clean-prepare-and-compile-tasks

Sample Ant clean, prepare, and compile tasks

<target name=”clean”>
<echo>=== CLEAN ===</echo>
<delete failonerror=”false”>
<fileset dir=”${dest.dir}” includes=”**/*”/>
</delete>
<delete dir=”${temp.dir}” />
</target>

<target name=”prepare” depends=”clean”>
<echo>=== PREPARE ===</echo>
<mkdir dir=”${dest.dir}” />
<mkdir dir=”${temp.dir}” />
<mkdir dir=”${temp.dir.lib}” />
<mkdir dir=”${temp.dir.meta-inf}” />
<mkdir dir=”${temp.dir.web-inf}” />
<mkdir dir=”${temp.dir.classes}” />
</target>

<target name=”compile” depends=”prepare”>
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files …</echo>
<javac debug=”on” srcdir=”${src.dir}” destdir=”${temp.dir.classes}” includes=”**/*”>
<classpath refid=”build.class.path” />
</javac>

<!– compile files on the src-tests path –>
<echo>Compiling ${src.tests.dir} files …</echo>
<javac debug=”on” srcdir=”${src.tests.dir}” destdir=”${temp.dir.classes}” includes=”com/**”>
<classpath refid=”build.class.path” />
</javac>
</target>

Tagged : / / / / / / / / / / / / / / / /

Samples/Examples of the Ant copy task – Guide

ant-copy-task

Samples of the Ant copy task

<copy file=”${resources.dir}/MANIFEST.MF” tofile=”${temp.dir.meta-inf}/MANIFEST.MF” overwrite=”true” />
<copy file=”${resources.dir}/managed-beans.xml” tofile=”${temp.dir.web-inf}/managed-beans.xml” overwrite=”true” />
<copy file=”${resources.dir}/navigation-rules.xml” tofile=”${temp.dir.web-inf}/navigation-rules.xml” overwrite=”true” />
<copy file=”${resources.dir}/monitoring-managed-beans.xml” tofile=”${temp.dir.web-inf}/monitoring-managed-beans.xml” overwrite=”true” />
<copy file=”${resources.dir}/monitoring-navigation-rules.xml” tofile=”${temp.dir.web-inf}/monitoring-navigation-rules.xml” overwrite=”true” />
<copy file=”${resources.dir}/faces-config.xml” tofile=”${temp.dir.web-inf}/faces-config.xml” overwrite=”true” />
<copy file=”${resources.dir}/log4j.properties” tofile=”${temp.dir.classes}/log4j.properties” overwrite=”true” />
<copy file=”${resources.dir}/commons-logging.properties” tofile=”${temp.dir.classes}/commons-logging.properties” overwrite=”true” />

<copy todir=”${temp.dir.classes}”>
<fileset dir=”${src.dir}”>
<include name=”**/*.xml”/>
<include name=”**/*.xsl”/>
<include name=”**/*.properties”/>
</fileset>
</copy>

<copy todir=”${dist}”>
<fileset dir=”${src}”
includes=”**/images/*”
excludes=”**/*.gif”
/>
</copy>

This copies all files in directories called images that are located in the directory tree defined by ${src} to the destination directory defined by ${dist}, but excludes all *.gif files from the copy.

<copy todir=”${dist}”>
<fileset dir=”${src}”>
<include name=”**/images/*”/>
<exclude name=”**/*.gif”/>
</fileset>
</copy>

The same as the example above, but expressed using nested elements.

<delete dir=”${dist}”>
<include name=”**/images/*”/>
<exclude name=”**/*.gif”/>
</delete>

Deleting the original set of files, the delete task can act as an implicit fileset.

Flatten directories when performing an Ant copy
Here’s a code snippet from an Ant build script where I begin with a hierarchical structure of jar files in my development environment, then flatten out all my lib subdirectories into one directory in my production environment when I copy all the jar files to my production library directory:

<!– build a temporary lib dir, and flatten out the jars into one folder –>

<copy todir=”${temp.dir.lib}” flatten=”true”>
<fileset dir=”${lib.dir}”>
<exclude name=”${cob.lib.dir}” />
<exclude name=”junit*” />
<include name=”**/*.jar”/>
<include name=”**/*.zip”/>
</fileset>
</copy>

 

Tagged : / / / / / / / / /

| SVN | Subversion | SVN pros and Cons| SVN Repository Planning | SVN Repository layout

svn-pros-and-cons

| SVN | Subversion | SVN pros and Cons| SVN Repository Planning | SVN Repository layout |

Subversion (SVN) Repository Layout

Single Project – One project per repository location

Pros

· Isolated revision numbers

· Isolated codebase

· Isolated security model

Cons

· Isolated codebase

· Multiple Urls to remember

· Multiple locations to maintain

Multi-Project Layout – Several projects in one repository

Pros

· Easy to merge code between projects

· Single url for all projects

· One repository to maintain

Cons

· Revision numbers span across all projects

· Harder to isolate users to appropriate repositories

Tagged : / / / / / / / / /