import-bot (20211) [Avatar] Offline
#1
[Originally posted by anantkgarg]

Hi,

I am using org.apache.tools.ant.Main.main(String[]) method providing it with
the required parameters from my application.
The problem now is that I have defined my own task and a proper <taskdef>
....>, its working fine, but after the execution of my task I am calling <ant>
antfile="filename.....> which after the successful execution exits my
application.
But I dont want the application to exit.Is there any way in which I can do
that using ant and also after successful execution do no exit the application.
The sample code and file I am using are:

1. java File from where I am calling the main method of
org.apache.tools.ant.Main class.

import org.apache.tools.ant.*;

public class Caller
{
public static void main(String []args){
args = new String[3];
args[0] = new String("-buildfile");
args[1] = new String("configmasterbuild.xml");
args[2] = new String("patch");
//args[3] = new String("-q");

org.apache.tools.ant.Main.main(args);

System.out.println("Hello World");
}
}
*****************************************************
2. aspconfigmasterbuild.xml
<?xml version="1.0"?>

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- iText, a JAVA - PDF library -->
<!-- $Id: build.xml,v 1.110 2003/05/02 13:55:34 blowagie Exp $ -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<project name="Patch" default="patch" basedir=".">
<taskdef name="mytask" classname="TemplateGeneratorTask"/>


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Applying the patch from a file -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

<target name="patch">

<mytask templateFile="aspconfigmaster.xml.template">
patchFile="aspDistName.patch" propertiesFile="asp_deployment.prop"
outputFile="./template/aspconfigmaster.xml.template" fmt="@ASPDISTNAME@_D"
devflag="no" />

<ant antfile="eGatewayConfig.xml" target="customize.prop.files.asp" />

</target>

</project>

******************************************
3.eGatewayConfig.xml

<project name="eGateway" default="customize.prop.files" basedir=".">

<!--<br /> Note: The target names in Ant are case-sensitive.<br /> <br /> For help on what Ant targets (build tasks) are available in this file,<br /> type "Ant -projecthelp -buildfile eGatewayConfig.xml" on the command<br /> line. <br /> -->

<property name="egateway.home" value="${user.dir}"/>

<!-- the directory (and sub-directories) to customize -->
<property name="customize.dir" value="${egateway.home}"/>

<!-- the Java property file containing replacement values -->
<!--<property name="property.file" value="deployment.prop" /> -->


<!-- ========== Executable Targets ======================================== -->



<!--<br /> Customize property files for a particular system. The variables in<br /> the configuration <br /> files are assumed to be in the format @some.variable@ . The variable<br /> values are <br /> supplied in the filtersfile in the format some.variable=value . This<br /> customization step <br /> will search for all files that end in .template and replace the<br /> variables in them. <br /> The updated files will have the same name except with the .template<br /> stripped off. The <br /> files with .template should be checked into CVS, while the new files<br /> without .template <br /> should not be checked into CVS. They are only needed at runtime.<br /> -->
<target name = "customize.prop.files" description = "Replace variables in<br /> config files">

<!-- Customize property files for new environment -->
<copy todir = "${customize.dir}/xml" overwrite = "yes">
<fileset dir = "${customize.dir}/template">
<patternset>
<include name = "**/*.template"/>
</patternset>
</fileset>
<filterset begintoken = "@" endtoken = "@">
<filtersfile file = "${property.file}"/>
</filterset>
<!-- remove .template from the file name for the configured file<br /> name -->
<mapper type="glob" from="*.template" to="*" />
</copy>

<!-- Special case for the propertystore directory: -->
<!-- Since JMX is reading all files in the propertystore -->
<!-- directory, even the *.template files, we need to -->
<!-- store the propertystore template files in a different -->
<!-- directory. Then, we'll move the final property -->
<!-- files over to the real propertystore directory. -->



</target>

<target name = "customize.prop.files.asp" description = "Setup ASP<br /> configuration">
<property name = "property.file" value = "asp_deployment.prop"/>
<antcall target = "customize.prop.files"/>
</target>

<target name = "customize.prop.files.district" description = "Setup<br /> District configuration">
<property name = "property.file" value = "dist_deployment.prop"/>
<antcall target = "customize.prop.files"/>
</target>

<target name = "customize.prop.files.school" description = "Setup School<br /> configuration">
<property name = "property.file" value = "school_deployment.prop"/>
<antcall target = "customize.prop.files"/>
</target>

<target name = "customize.prop.files.dev" description = "Setup Development<br /> configuration">
<property name = "property.file" value = "dev_deployment.prop"/>
<antcall target = "customize.prop.files"/>
</target>
</project>
import-bot (20211) [Avatar] Offline
#2
Re: Problem using Main.main()
[Originally posted by steve_l]

Ant calls System.exit() because the dev team doesnt want you to invoke Ant
that way in embedded use. That entry point does things like take over
System.out so that contained Java code has its output routed to listeners, and
the like, so you could find lots of surprises if you invoke Ant that way.

Look at 'Using Tasks Outside of Ant' in the ant manual to see how to create
and populate your own project.