dcsimg
Created own task and problem with static initialization
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sascha_Spiekermann
Posted On:   Tuesday, February 7, 2006 09:47 AM

Hello I've written my own task which uses a helper class with just static methods, a dummy copy of the helper is displayed as Container.java. import java.util.HashMap; public class Container { private static final HashMap basicProperties = new HashMap(); static { System.out.println("static construktor"); } public static void doIt() { System.out.println("DoIt"); } } If I use my task three times in one build.xml and use Container.doIt() in my execute() method, I get three times "static construktor" and "DoIt" (and Container.basicProperties is initialized three times). After invest   More>>

Hello

I've written my own task which uses a helper class with just static methods, a dummy copy of the helper is displayed as Container.java.

			
import java.util.HashMap;
public class Container
{
private static final HashMap basicProperties = new HashMap();
static
{
System.out.println("static construktor");
}

public static void doIt()
{
System.out.println("DoIt");
}
}

If I use my task three times in one build.xml and use Container.doIt() in my execute() method, I get three times "static construktor" and "DoIt" (and Container.basicProperties is initialized three times). After investigation I found out that in every static {} another instance of AntClassLoader2 is used as the ClassLoader for my Container object. How can I achive that my static method/fields keep static?

-Sascha    <<Less

Re: Created own task and problem with static initialization

Posted By:   ankush_purwar  
Posted On:   Tuesday, February 7, 2006 05:34 PM

Is it possible for you to put this class in your system classpath ?

The problem will be solved by doing this.
About | Sitemap | Contact