DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=30001>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=30001 unable to replace(re-set) property values in ant Projects Summary: unable to replace(re-set) property values in ant Projects Product: Ant Version: 1.6.1 Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Major Priority: Other Component: Other AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] I have tried recently to call ant through java using the ANT java API. In order to reproduce the bug you should use the files cited below: The java.class through which ant is called. /* * Created on Jul 8, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ package org.security.ac.utils; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.helper.ProjectHelper2; import org.apache.tools.ant.PropertyHelper; import java.io.File; /** * @author iprigg * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class AntInvoker { String antfile; Project antProject; PropertyHelper propertyHelper; ProjectHelper projectHelper; public AntInvoker(String filename) { antProject=new Project(); projectHelper=new ProjectHelper2(); propertyHelper=PropertyHelper.getPropertyHelper(antProject); antfile=filename; File f=new File(filename); antProject.init(); projectHelper.parse(antProject,f); } public void createServiceJar(String serviceName) { if (propertyHelper.getProperty(null,"servicename")==null) propertyHelper.setNewProperty (null,"servicename",serviceName); else propertyHelper.setProperty (null,"servicename",serviceName,false); if (propertyHelper.getProperty(null,"securitydomain")==null) propertyHelper.setNewProperty (null,"securitydomain","java:/jaas/"+serviceName); else propertyHelper.setProperty (null,"securitydomain","java:/jaas/"+serviceName,false); if (propertyHelper.getProperty(null,"files2parse")==null) propertyHelper.setNewProperty (null,"files2parse","polosService2/"+serviceName+"Bean.java"); else propertyHelper.setProperty (null,"files2parse","polosService2/"+serviceName+"Bean.java",false); if (propertyHelper.getProperty(null,"jar.name")==null) propertyHelper.setNewProperty (null,"jar.name",serviceName+".jar"); else propertyHelper.setProperty (null,"jar.name",serviceName+".jar",false); System.out.println("servicename:"+antProject.getProperty ("servicename")); System.out.println("source file:"+antProject.getProperty ("files2parse")); System.out.println("jar file:"+antProject.getProperty ("jar.name")); System.out.println("security-Domain:"+antProject.getProperty ("securitydomain")); antProject.executeTarget("clear"); antProject.executeTarget("jar"); } public void createAllServices() { for (int i=1;i<=2;i++) { createServiceJar("Service"+i); } } public static void main(String[] args) { AntInvoker ant=new AntInvoker("build.xml"); ant.createAllServices(); } } The corresponding build.xml file is the one below: *************build.xml begin**************** <project name="TestService" default="compile" basedir="."> <!-- Give user a chance to override without editing this file (and without typing -D each time they run it) --> <property file="ant.properties" /> <property name="Name" value="Template"/> <property name="version" value="1.1"/> <property name="src.dir" value="src"/> <property name="build.dir" value="bin"/> <property name="build.classes.dir" value="${build.dir}/classes"/> <property name="build.jars.dir" value="${build.dir}/jars"/> <property name="src.ejb.dir" value="${build.dir}/ejbsrc"/> <property name="ejb.dd.dir" value="${build.dir}/META-INF"/> <property name="web.dd.dir" value="${build.dir}/WEB-INF"/> <property name="xdoclet.force" value="true"/> <property name="jboss.deploy.dir" value="${jboss.home}/server/ ${jboss.configuration}/deploy"/> <property name="jboss.lib.dir" value="${jboss.home}/server/ ${jboss.configuration}/lib"/> <path id="base.path"> <pathelement location="${tomcat.home}/server/lib/catalina.jar"/> <pathelement location="${build.dir}" /> <!-- append the xdoclet path --> <pathelement location="${xdoclet.home}/lib/xdoclet.jar"/> <!-- append the log4j path --> <pathelement location="${jboss.home}/client/log4j.jar" /> <!-- append the ant path --> <pathelement location="${ant.home}/lib/ant.jar" /> <!-- append the tools path --> <pathelement location="${java.home}/lib/tools.jar" /> <!-- append the J2EE path --> <fileset dir="${jboss.lib.dir}"> <include name="*.jar"/> </fileset> <fileset dir="${jboss.home}/lib"> <include name="*.jar"/> </fileset> <fileset dir="${jboss.home}/client"> <include name="*.jar"/> </fileset> </path> <property name="class.path" refid="base.path"/> <target name="init"> <tstamp/> <mkdir dir="${build.classes.dir}"/> <mkdir dir="${build.jars.dir}"/> <mkdir dir="${ejb.dd.dir}"/> <mkdir dir="${web.dd.dir}"/> <mkdir dir="${src.ejb.dir}"/> </target> <!-- =================================================================== --> <!-- EjbDoclet Task --> <!-- =================================================================== --> <target name="generateEJBs" depends="init"> <echo message="servicename=${servicename}"/> <echo message="securitydomain=${securitydomain}"/> <echo message="files2parse=${files2parse}"/> <echo message="jar.name=${jar.name}"/> <taskdef name="ejbdoclet" classname="xdoclet.ejb.EjbDocletTask"> <classpath refid="base.path"/> </taskdef> <ejbdoclet sourcepath="${src.dir}" destdir="${src.ejb.dir}" mergedir="${ejb.dd.dir}" classpathref="base.path" excludedtags="@version,@author,@todo" ejbspec="${ejb.version}" force="${xdoclet.force}"> <fileset dir="${src.dir}" defaultexcludes="yes"> <include name="${files2parse}"/> </fileset> <deploymentdescriptor destdir="${ejb.dd.dir}" validatexml="false" mergedir="${ejb.dd.dir}"/> <remoteinterface pattern="{0}Remote" /> <homeinterface pattern="{0}Home" /> <localinterface pattern="{0}Local"/> <localhomeinterface pattern="{0}HomeLocal" /> <jboss version="${jboss.version}" securitydomain="${securitydomain}" xmlencoding="UTF-8" destdir="${ejb.dd.dir}" validatexml="false" datasource="${datasource.name}"/> </ejbdoclet> </target> <!-- =================================================================== --> <!-- Compiles the source code --> <!-- =================================================================== --> <target name="compile"> <copy file="${src.dir}/${files2parse}" todir="${src.ejb.dir}/polosService2" overwrite="true"/> <javac destdir="${build.classes.dir}" debug="on" deprecation="off" optimize="on"> <classpath> <path refid="base.path"/> </classpath> <src> <!-- <path path="${src.dir}"/> --> <path path="${src.ejb.dir}"/> </src> <include name="**/*.java"/> </javac> </target> <!-- =================================================================== --> <!-- Creates the jar archives --> <!-- =================================================================== --> <target name="jar" depends="compile"> <jar jarfile="${build.jars.dir}/${jar.name}"> <fileset dir="${build.classes.dir}"> <include name="**/*"/> </fileset> <fileset dir="${build.dir}" includes="META-INF/**"> </fileset> </jar> </target> <target name="deploy" depends="jar"> <copy file="${build.jars.dir}/${jar.name}" todir="${jboss.deploy.dir}" overwrite="yes"/> </target> <target name="undeploy"> <delete file="${jboss.deploy.dir}/${jar.name}"/> </target> <target name="clear"> <delete> <fileset dir = "${build.dir}/META-INF" includes="**/*"/> <fileset dir = "${build.dir}/ejbsrc" includes="**/*"/> <fileset dir = "${build.dir}/classes" includes="**/*"/> </delete> </target> <target name="all-in-one"> <taskdef name="ejbdoclet" classname="xdoclet.ejb.EjbDocletTask"> <classpath refid="base.path"/> </taskdef> <ejbdoclet sourcepath="${src.dir}" destdir="${src.ejb.dir}" mergedir="${ejb.dd.dir}" classpathref="base.path" excludedtags="@version,@author,@todo" ejbspec="${ejb.version}" force="${xdoclet.force}"> <fileset dir="${src.dir}" defaultexcludes="yes"> <include name="${files2parse}"/> </fileset> <deploymentdescriptor destdir="${ejb.dd.dir}" validatexml="false" mergedir="${ejb.dd.dir}"/> <remoteinterface pattern="{0}Remote" /> <homeinterface pattern="{0}Home" /> <localinterface pattern="{0}Local"/> <localhomeinterface pattern="{0}HomeLocal" /> <jboss version="${jboss.version}" securitydomain="${securitydomain}" xmlencoding="UTF-8" destdir="${ejb.dd.dir}" validatexml="false" datasource="${datasource.name}"/> </ejbdoclet> <copy file="${src.dir}/${files2parse}" todir="${src.ejb.dir}/polosService2" overwrite="true"/> <javac destdir="${build.classes.dir}" debug="on" deprecation="off" optimize="on"> <classpath> <path refid="base.path"/> </classpath> <src> <!-- <path path="${src.dir}"/> --> <path path="${src.ejb.dir}"/> </src> <include name="**/*.java"/> </javac> <jar jarfile="${build.jars.dir}/${jar.name}"> <fileset dir="${build.classes.dir}"> <include name="**/*"/> </fileset> <fileset dir="${build.dir}" includes="META-INF/**"> </fileset> </jar> </target> </project> *************build.xml end**************** I also used the following ant.properties file: *************ant.properties begin**************** # ATTENTION: this is an example file how to overwrite settings in this project # Please adjust the settings to your needs. install.drive=d: #Set the java home java.home=${install.drive}/j2sdk1.4.1 #Set the ant home path ant.home=${install.drive}/apache-ant-1.6.1 # Set the path to the runtime JBoss directory containing the JBoss application server # ATTENTION: the one containing directories like "bin", "client", "server" etc. jboss.home=${install.drive}/jboss-3.2.3 #set the embedded tomcat home dir tomcat.home=${jboss.home}/tomcat-4.1.x # Set the configuration name that must have a corresponding directory under # <jboss.home>/server jboss.configuration=default # Set the EJB version you want to use (1.1 or 2.0, see XDoclet's <ejbdoclet> attribute "ejbspec") ejb.version=2.0 # Set the path to the root directory of the XDoclet distribution (see # http://www.sf.net/projects/xdoclet) xdoclet.home=${install.drive}/xdoclet # Set the JBoss version you want to use (2.4, 3.0 etc., see XDoclet's <jboss> attribute "version") jboss.version=3.0 *************ant.properties end**************** The build.xml file is a little bit complicated but as you see in the java source I only call the simple "clear" and "jar" targets. The latter calls the "compile" target also. Note that in order to run the above properly you should have a "src" directory in the same level with the build.xml file, which should contain a "polosService2" directory with two files: Service1Bean.java and Service2Bean.java. So if you have everything in a test directory. The internal file structure should look something like that: -->test--> src------------>polosService2--> Service1Bean.java build.xml Service2Bean.java ant.properties Upon running the file a bin directory is created, with several subdirectories. Based on the definitions contained in the build.xml running the program should normally create 2 jars inside the bin/jars directory. One named service1.jar and one named service2.jar. However this is not the case. Only the first jar is created, as if the setProperty(..) commands did not work. What is strange is that the output of the program (the println(..) commands) indicates that the the properties were replaced successfully. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]