Hi,
I have written a java code to execute ant targets via Servlet. I have given the code below.
The build.xml file is as follows.
When the method antTest() is invoked, I got the following output.
When I executed the build.xml using the command prompt (i.e. using the command "ant -f build.xml display"), I got the following output.
I would like to have the following.
1) I expect the output from the java code should also display the same lines as in the output from command prompt. Please let me know the way to do so.
2) I want to log the output of the ant target to a log file when executing from java.
3) Is there any other way to run ant targets as we are running from the command prompt. That is if we have a string variable having the value "ant -f build.xml display", we could have to make this as the command to execute ant target. Is this possible? If so please let me know the way to implement.
I have written a java code to execute ant targets via Servlet. I have given the code below.
Code:
import org.apache.tools.ant.*;
import org.apache.catalina.ant.*;
.
.
.
.
public void antTest()
{
BuildLogger logger = new DefaultLogger();
logger.setMessageOutputLevel(Project.MSG_INFO);
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.out);
logger.setEmacsMode(true);
ProjectHelper ph = ProjectHelper.getProjectHelper();
Project p = new Project();
p.addBuildListener(logger);
p.init();
p.addReference("ant.projectHelper", ph);
ph.parse(p, new File(sctx.getRealPath("/")+"bin/build.xml"));
p.executeTarget("display");
}
Code:
<project name="Web Application" default="display" basedir=".">
<property file="${user.home}/build.properties"/>
<property file="build.properties"/>
<target name="init">
<tstamp/>
</target>
<target name="display" description="Deletes the Web Application's war directory and war file">
<echo message="This line is displaying from ant target ..."/>
</target>
</project>
Code:
This line is displaying from ant target ...
Code:
Buildfile: build.xml
Trying to override old definition of datatype resources
display:
[echo] This line is displaying from ant target ...
BUILD SUCCESSFUL
Total time: 0 seconds
1) I expect the output from the java code should also display the same lines as in the output from command prompt. Please let me know the way to do so.
2) I want to log the output of the ant target to a log file when executing from java.
3) Is there any other way to run ant targets as we are running from the command prompt. That is if we have a string variable having the value "ant -f build.xml display", we could have to make this as the command to execute ant target. Is this possible? If so please let me know the way to implement.
Comment