Ant tasks for building and deploying applications and adapters
Prerequisites
Ant tasks are supplied with MobileFirst Server and the MPF Command Line Interface. Use them to build and deploy the applications, adapters, and projects.
A typical use of these Ant tasks is to integrate them with a central build service called manually or periodically on a central build server.
Make sure Apache Ant is installed. The minimum supported version of Ant is listed in System requirements for using MPF.
Apache Ant 1.8.4 is included in MobileFirst Server.
cd MF_HOME/shortcuts/ ./ant
These scripts do not require specific environment variables. If the JAVA_HOME environment variable is set, the scripts accept it.
See
Build from a IBM Worklight v6.0.0 project and deploying to a v6.3.0 MobileFirst Server
If we want to build apps and adapters from a IBM Worklight v6.0.0 project and deploy them to a v6.3.0 MobileFirst Server, you might think that all we need to do is add a <taskdef> definition as shown in the following Ant task.
- WL600_DIR is the directory where you installed IBM Worklight v6.0.0.
- MF_HOME is the directory where you installed IBM MobileFirst Platform Server v6.3.0.
<taskdef resource="com/worklight/ant/defaults.properties"> <classpath> <pathelement location="WL600_DIR/WorklightServer/worklight-ant.jar" /> </classpath> </taskdef>
<taskdef resource="com/worklight/ant/deployers/antlib.xml"> <classpath> <pathelement location="MF_HOME/WorklightServer/worklight-ant-deployer.jar" /> </classpath> </taskdef>However, the JAR files worklight-ant.jar and worklight-ant-deployer.jar conflict, because they contain classes with the same name in different versions.
To solve this conflict, we must split the script into two different Ant files: one to build v6.0.0 artifacts and the other to deploy them to the v6.3.0 server, as shown in the following examples.
- Ant script to build v6.0.0 artifacts
<project basedir="." default="build-and-deploy"> <property name="project.name" value="MyProject" /> <property name="wl.server" value="http://localhost:9080/${project.name}/" /> <property name="wl.project.location" location="${basedir}/${project.name}" /> <property name="output.location" location="${wl.project.location}/bin" /> <property name="wl.adapter.name" location="MyAdapter" /> <property name="wl.application.name" location="MyApplication" /> <property name="worklight-ant" location="worklight-ant.jar" /> <target name="init"> <taskdef resource="com/worklight/ant/defaults.properties"> <classpath> <pathelement location="${worklight-ant}" /> </classpath> </taskdef> </target> <target name="build"> <adapter-builder folder="${wl.project.location}/adapters/${wl.adapter.name}" destinationFolder="${output.location}"/> <app-builder applicationFolder="${wl.project.location}/apps/${wl.application.name}" outputfolder="${output.location}" worklightserverhost="${wl.server}" nativeprojectprefix="${project.name}"/> </target> <target name="deploy"> <ant antfile="deploy.xml" inheritall="true" /> </target> <target name="build-and-deploy" depends="init,build,deploy" /> </project>
- Ant script to deploy v6.0.0. artifacts to a v6.3.0 server
<project basedir="." default="deploy"> <property name="worklight-ant-deployer" location="worklight-ant-deployer.jar" /> <target name="init"> <taskdef resource="com/worklight/ant/defaults.properties"> <classpath> <pathelement location="${worklight-ant-deployer}" /> </classpath> </taskdef> </target> <target name="deploy" depends="init"> <wladm url="https://server-address:secure-port/worklightadmin" user="username" password="password"> <deploy-app runtime="project-name" file="${output.location}/${wl.application.name}-all.wlapp"/> <deploy-adapter runtime="project-name" file="${output.location}/${wl.adapter.name}.adapter"/> </wladm> </target> </project>
Parent topic: Deploy MobileFirst applications to test and production environments