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 : / / / / / / / / / / / / / / / /

How to Integrate Subversion Into Your Ant Build ? – Step by step guide

svn-integration-in-ant-build

SVNAnt
SVNAnt is an Ant task allowing you to interact with Subversion within the convenience of your Ant build script. No more writing custom scripts to get the revision of your repository to tag your release jars. Nor do you have to make command line calls to checkout your latest and greatest as part of your continuous integration process. With SVNAnt, you have the familiarity of the Ant syntax and the flexibility you need for interacting with Subversion.
Features
SVNAnt is a full-featured Subversion client capable of using the native Java bindings or command-line wrappering depending on which is available. Beyond how it works, SVNAnt allows you to do all svn subcommands but the following:

blame cleanup help list
lock log merge propedit
proplist resolved unlocked  

If the svn subcommand is not listed here, you can use it in your Ant build file. Before we continue start using SVNAnt, we have to install it and configure Ant to use it.
Installation
Now that we know what SVNAnt is and what its features are, lets install SVNAnt so that you can begin to use SVNAnt to access Subversion within your Ant build cycle.

Step 1. (Download, Compile and Extract)
This step will download, compile, and “install” the latest version of SVNAnt.
1.1 Using Subversion, checkout the SVNAnt project located here: http://subclipse.tigris.org/svn/subclipse/trunk/svnant
1.2 From the command line, while inside of the location where you checked out SVNAnt to, run “ant makeDistrib”
1.3 Extract the .zip file created in the build directory of your SVNAnt source to a location of your choosing

Step 2. (Modify your build.xml)
The next step is to tell Ant how to find your SVNAnt task by adding the following to your build.xml file:
<path id= “svnant.classpath” >
<fileset dir= “/PATH/TO/YOUR/EXTRACTED/SVNANT-ZIP” >
<include name= “*.jar” />
</fileset>
</path>

<typedef resource=”org/tigris/subversion/svnant/svnantlib.xml” classpathref=”svnant.classpath” />
That should be it. I know that it appears to be too good to be true so lets verify this.

Step 3. (Verify installation)
Building upon Step 2, lets create a new ant task that will use the wcVersion feature of SVNAnt to get some information about your repository from a local working copy:
<target name=”testSVNAnt”>
<svn>
<wcVersion path= “PATH/TO/YOUR/WORKINGCOPY” />
</svn>

<echo message= “Subversion repository url: ${repository.url}” />
</target>
(Note: In the event that you need to pass credentials to Subversion, look here.)
The output should be something similar to this:
$ ant testSVNAnt

Buildfile: build.xml

testSVNAnt:
[svn] <WcVersion> started …
[svn]  finished.
[echo] Subversion repository url: http://svn.apache.org/repos/asf/incubator/openejb/trunk

BUILD SUCCESSFUL
Total time: 43 seconds

Pat yourself on the back. You have successfully installed SVNAnt and you are ready to implement Subversion into your Ant build cycle. Instead of us going through each available feature for SVNAnt, please view the SVNAnt Documentation. Now lets talk about why you may want to use SVNAnt to allow for Subversion interaction inside of your Ant build cycle.

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