Here’s the situation: I trying to make a ant test script that does the following
1 – Runs a utility to create test data
2 – Runs junit suite
3 – Runs a utility to clean up test data.
The problems is parts 2 & 3 need to access to some static fields of the utility in 1 (e.g. generated unique names of test data). This issue I’m having is that it the static fields of the class are null when I try to access them as though the java task in #1 was run in a separate process or using a different classloader (I’ve tried setting the attribute fork=”false” on the java task and using -Dant.reuse.loader=true on the cmd line). Any ant gurus know what’s going on here?
Since you are dealing with different class loaders, you’ll never get past one’s class loader finding the “wrong” instance of the exact same class and hence using the “wrong” static value. You need to do the communications between the ant invocations via a file. A temporary file will likely not do, as it will likely be removed before the second set of ant classes get a chance to work with it.
There are two issues, the generation of suitable property values, and the transmission of them between ant calls. Perhaps you don’t need all of this since your situation might already generate suitable identifiers, but it’s here if you do.
To generate suitable values, one ant process should the propertyfile task to generate the appropriate names, with the per-run changing identifier as part of the name
Subsequent ant processes can then just source in the original ant process’s generated property file.
Which will have the effect of defining