Creating a Windchill Ant script
Introduction
This article is a tutorial taking the user through the steps necessary to create and run an Ant script for Windchill. Ant is a very useful tool to build source, but with some basic techniques shown here it can also be used to script a number of actions related to a administration of the customization. A typical usage would be installation of a PDMLink™ or ProjectLink™ customization where the ant script will need to add files, update XML files and compile resource bundles. A major advantage from using simple batch or shell files is that ,as Ant is platform independent, we can develop on Windows and and deploy using the same scripts on Unix.
- Running Ant in Windchill
- Setting up basic parameters
- Updating a Windchill property
- Compiling a resource bundle
Running Ant in Windchill
Ant is pre-installed in all Windchill Installations, so we do not need to install anything. Ant can be executed from a Windchill shell as follows
ant -f [script]In addition a very useful library is also pre-installed called ant-contrib which adds features, such as if-then-else, these allows us to use Ant outside it’s normal domain of managing the build process.
Setting up basic parameters
In order to setup our Ant script we often need to have various parameters available, some of which are OS dependent. So for this we can use a setup task
<target name="setup"> <echo message="Setting up environment"/> <!-- The Windchill home & codebase taken from the env --> <property environment="env"/> <property name="wcinstall" value="${env.WT_HOME}"/> <property name="codebase" value="${wcinstall}/codebase"/> <!-- The O/S dependent xconf command --> <condition property="xconfCommand" value="${wcinstall}/bin/xconfmanager.bat" > <os family="windows"/> </condition> <property name="xconfCommand" value="${wcinstall}/bin/xconfmanager"/> <!-- The O/S dependent ant command --> <condition property="antcmd" value="ant.bat" > <os family="windows"/> </condition> <property name="antcmd" value="ant" /> <!-- Custom task for updating XML with XPath --> <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" /> <!-- ant-contrib to allow us to use if-then-else --> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/> </target>
Updating a Windchill property
Windchill has a standard technique to update it’s many property files such as wt.properties. This is controlled by a master file called site.xconf that looks as follows
<Configuration xmlns:xlink="http://www.w3.org/1999/xlink"> <Property name="installedProduct.location.Apache" overridable="true" targetFile="codebase/WEB-INF/ieWebServerLocation.txt" value="w:\ptc\Apache"/> <Property name="wt.java.cmd" overridable="true" targetFile="codebase/wt.properties" value="w:\ptc\Java\jre\bin\java.exe"/> ..... </Configuration>
You can update it as follows using the xconfmanager command
<target name="addlistener" depends="setup"> <echo message="Adding listener wt.properties"/> <exec executable="${xconfCommand}"> <arg value="-tcodebase/wt.properties"/> <arg value="-p"/> <arg value="-s wt.services.service.5463=ext.myclient.MyClientListener/ext.myclient.MyClientListener" /> </exec> </target>
Note the the dependency to setup
Compiling a resource bundle
<target name="resourcebuild" depends="setup"> <echo message="Building resource bundles"/> <exec executable="${wcinstall}/ant/bin/${antcmd}"> <arg value="-f"/> <arg value="${wcinstall}/bin/tools.xml"/> <arg value="bundle"/> <arg value="-Dbundle.input=ext.myclient.MyClientRB"/> <arg value="-Dbundle.buildLocales=true"/> </exec> <delete file="${codebase}/tools.properties"/> </target>