Most of the time, we need to embed Ant in a java program. So if you need to call Ant task inside Java program, this piece of code will do it.
Required Jars:
Ant.jar
Ant-Launcher.jar
tools.jar*
you can get the jar file by just using the class org.apache.tools.ant.launch.Launche through this Jar finder Website
Source Code:
import org.apache.tools.ant.launch.Launcher;
public class LaunchAnt
{
public static void main(String args[])
{
String[] parameters = new String[2];
parameters[0]="-buildfile";
parameters[1] = "build.xml";
Launcher.main(parameters);
}
}
Note:
tools.jar will be available at the location
C:\ProgramFiles\ - Windows
usr/lib/jvm/ - Linux
Install Java in Linux
Required Jars:
Ant.jar
Ant-Launcher.jar
tools.jar*
you can get the jar file by just using the class org.apache.tools.ant.launch.Launche through this Jar finder Website
Source Code:
import org.apache.tools.ant.launch.Launcher;
public class LaunchAnt
{
public static void main(String args[])
{
String[] parameters = new String[2];
parameters[0]="-buildfile";
parameters[1] = "build.xml";
Launcher.main(parameters);
}
}
Note:
tools.jar will be available at the location
C:\ProgramFiles\
usr/lib/jvm/ - Linux
Install Java in Linux
Comments
Thanks for Sharing