Category Archives: Apache Ant

sending emails from ANT

Hi All,

This is perhaps the most hottest feature of ANT to send emails from build script. By this task we can achieve email notifications about build creation, Send code metrics, code reviews reports etc.

Note you need to configure SMTP port, before using that.

<mail mailhost=”smtp.myisp.com” mailport=”1025″ subject=”Test build”>
<from address=”config@myisp.com”/>
<replyto address=”me@myisp.com”/>
<to address=”all@xyz.com”/>
The ${buildname} nightly build has completed
<attachments>
<fileset dir=”dist”>
<include name=”**/*.zip”/>
</fileset>
</attachments>
</mail>


Thanks
R Vashi

Using ANT to compile Flex files

Hi All,

The below example will show how to use ANT to compile Flex files to generate .SWF files.

Step 1: Install FLEX SDK3.1   e.g   c:/flex3.1

Step 2: Create a build.xml    e.g. build.xml

Step 3: Add the below ant task defination  in the Build.xml
<taskdef resource=”flexTasks.tasks” classpath=”c:/flex3.1/ant/lib/flexTasks.jar”/>

Step 4: Crate an Ant Task
<target name=”compileFlex”>
<mxmlc file=”/flex/src/Index.mxml”
incremental=”true”
debug=”false”
optimize=”true”
warnings=”false”
services=”flex/services-config.xml”
output=”build/project/view/index.swf”
classpath=”c:/flex3.1/ant/lib/flexTasks.jar”>
<load-config filename=”c:/flex3.1/frameworks/flex-config.xml”/>
<compiler.library-path dir=”lib/swc” append=”true”>
<include name=”*.swc” />
</compiler.library-path>

</mxmlc>

</target>

Thanks

R Vashi.

Using a separate property file in Ant Script

Hi,

The below example will demonstarte usage of a separate property file in Ant Script

Step1: Define a property file.
File: build.properties
——————————
server.name=localhost
server.port=8080
server.scheme=http
——————————–

Step 2: Write ANT Script
File: build.xml
—————————————
<?xml version=”1.0″?>
<project name=”MyProject”basedir=”.”>
<target name=”properties.localfile”>
<property file=”build.properties”/> <!– Loads the property file –>
<echo message=”Server URL: ${server.url}”/>
<echo message=”Server Port: ${server.port}”/>
<echo message=”Server Scheme: ${server.url}”/>
</target>
</project>
————————————-

Thanks
R Vashis

Creating a Connection Pool using ANT in Weblogic

Hi

Managing weblogic through ANT is very easy and handy sometimes, Few days back I was just trying Connection pool creation using Apache ANT, So wants to share with you all.

Steps 1:
On Windows set the weblogic env using setWLSEnv.cmd(bea/wlseerverx.x/servers/bin), if you dont have Weblogic, Try putting weblogic.jar in the classpath

Step 2

Create a ANT Script.

<target name=”createPool”>
<wlconfig url=”t3://localhost:6001″ username=”weblogic” password=”weblogic”>
<query domain=”admin_domain” type=”Server” name=”AdminServer” property=”AdminServer”/>
<create type=”JDBCConnectionPool” name=”OneSourceConnectionPool”>
<set attribute=”DriverName”    value=”oracle.jdbc.OracleDriver”/>
<set attribute=”InitialCapacity” value=”15″/>
<set attribute=”MaxCapacity” value=”50″/>
<set attribute=”StatementTimeout” value=”600″/> OR Leave it to default -1
<set attribute=”Password” value=”PASSWORD”/>
<set attribute=”Properties” value=”user=USER_NAME”/>
<set attribute=”RefreshMinutes” value=”0″/>
<set attribute=”StatementCacheSize” value=”0″/>
<set attribute=”ShrinkPeriodMinutes” value=”15″/>
<set attribute=”ShrinkingEnabled” value=”true”/>
<set attribute=”TestConnectionsOnRelease” value=”true”/>
<set attribute=”TestConnectionsOnReserve” value=”true”/>
<set attribute=”TestConnectionsOnCreate” value=”true”/>
<set attribute=”TestTableName” value=”SQL SELECT 1 FROM DUAL”/>
<set attribute=”URL” value=”DB_URL”/>
<set attribute=”Targets” value=”${AdminServer}”/>
</create>
</wlconfig>
</target>

After running the ANT Task you will see the following output in the console.

If you want to configure some other types of Connection pool, Do check the MBean associated with that type(if you have weblogic access, see the right side info, and click on<> link,  a new pop up will open and see the MBean name for that type.

Note: Always use t3 protocol instead of HTTP while connecting Weblogic using ANT.


Thanks
R Vashi

Creating builds with build version in ANT

Hi All,

We can generate builds with the build version information using ANT, All we have to do is to create a separte properties files, save it parallel to the Build.xml.

Step 1: Load the properties file from outside
<property file=”build.properties”/> [inside the prop define key/value pair build_version=version 1.2.4]

Step 2: Specify the Vesrion information in the META-INF of the WAR/EAR using the below code.

<jar destfile=”build/war_name.war”>

<zipfileset dir=”${dist}”/>

<manifest>

<attribute name=”Built-By” value=”Date-${DATE_TIME}- Vesrion-${build_version}”/>

</manifest>

</jar>

Thanks
R Vashi

Creating a WAR/EAR with current date and time

Hi All,

Sometime when we are building war/ear very frequently using ANT specially during product pre release days then it become very difficult to maintain which dist has been generated when. To track that we can add the details in the META-INF of the war/ear using ANT.

<jar destfile=”build/war_name.war”>
<zipfileset dir=”${dist}”/>
<manifest>
<attribute name=”Built-By” value=”Date-${DATE_TIME}- Vesrion-${build_version}”/>
</manifest>
</jar>

Thanks

R Vashi