DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24677>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24677 Static member values lost without given CLASSPATH environment Summary: Static member values lost without given CLASSPATH environment Product: Ant Version: 1.5.4 Platform: PC OS/Version: BeOS Status: NEW Severity: Normal Priority: Other Component: Core AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] We wrote two own tasks (Task1 and Task2), which references another class (CounterHelper) with a static int member ( counter ). Task1's and Task2's execute methods create an instance of CounterHelper and increment it's static member counter. After this the value of counter is sent to stdout. ############################################################################### package staticant; import org.apache.tools.ant.Task; public class Task1 extends Task { public void execute(){ CounterHelper ch = new CounterHelper(); ch.incCounter(); System.out.println("Task1: "+ ch.getCounter()); } } package staticant; import org.apache.tools.ant.Task; public class Task2 extends Task { public void execute(){ CounterHelper ch = new CounterHelper(); ch.incCounter(); System.out.println("Task2: "+ ch.getCounter()); } } package staticant; public class CounterHelper { protected static int counter = 0; public CounterHelper() { } public int getCounter() { return counter; } public void incCounter() { counter++; } public void setCounter(int counter) { this.counter = counter; } } ############################################################################### We also created a suitable build.xml file like that: ############################################################################### <?xml version="1.0"?> <!DOCTYPE project> <project name="AntProject" default="main2" basedir="."> <taskdef name="mytask1" classname="staticant.Task1" classpath="classes"/> <taskdef name="mytask2" classname="staticant.Task2" classpath="classes"/> <target name="main2" depends="main"> <mytask2/> </target> <target name="main"> <mytask1/> </target> </project> ############################################################################### We expected that during execution of target "main" CounterHelper.counter is set to value 1 and during execution of target "main2" CounterHelper.counter is then set to value 2. But we got following result: ############################################################################### Buildfile: build.xml main: [mytask1] Task1: 1 main2: [mytask2] Task2: 1 BUILD SUCCESSFUL Total time: 4 seconds ############################################################################### ???????????? After some terrible nights of "try and error" :) we found, that the result depends on setting (or unsetting) of the CLASSPATH environment variable to our target task classes. In the "Feadback and Troubleshooting" section we also read: "Ant does not need the CLASSPATH variable defined to anything to work." So we learned, that don't setting the CLASSPATH brings the result above and setting the CLASSPATH like export CLASSPATH=:classes //points to our target task classes we got the following expected result: Buildfile: build.xml main: [mytask1] Task1: 1 main2: [mytask2] Task2: 2 BUILD SUCCESSFUL Total time: 4 seconds We tested this using ant version 1.5.1, 1.5.4 on Linux or using JBuilder on Windows got the same behaviour. What's going wrong? --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]