Friday, June 25, 2010

Invoke ANT targets programmatically using java

You can invoke ant targets programmatically with java using below code. You need to be sure that the jar files inside ANT_HOME\lib are included in project.


import java.io.File;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;

public class Test {
public static void runAnt(){
File buildFile = new File("build.xml");
if(!buildFile.exists()){
System.out.println("ERROR :: File "+buildFile.getAbsolutePath()+" does not exist");
}
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
}
public static void main(String... args){
runAnt();
}
}

Wednesday, June 23, 2010

Build and Deploy SOA Composites using ANT targets

The steps to build and deploy a SOA composite using an ANT target of build.xml is demonstrated in the current post.

Steps
=====
1. Download build.properties and build.xml.
2. Place the above two files inside build or deploy folder of the composite project. i.e. if HelloWorldProject is the directory of the composite project, then these files should be located inside HelloWorldProject/build or HelloWorldProject/deploy
3. Change the property values of build.properties file as per your scenario. The documentation above each property should be self explanatory.
4. Ensure that you have ANT has been installed and paths have been property set in environment. You can find more details of installing ANT here
5. Now open the command promt and change to the directory where the above two downloaded files have been placed.
6. Use the three targets defined in build.xml as explained below ::
- If you require only to build the composite SAR, then type "ant compile-package"
- If you already have the jar and want to deploy onto SOA server, then type "ant deploy"
- If you want to both build and deploy, then type "ant buildAndDeploy" or just typing ant should suffice as buildAndDeploy has been given as the default target in build.xml