Why do not use .java instead of .xml as config file?
For example:
My config file is C:\\T.java
In the static block of class T we can our stuff.
Use com.sun.tools.javac.Main to compile T.java and load the class
when the container starts.
Code:/* *compile the config file T.java */ String dirStr = "C:\\"; String srcFileName = "T.java"; File dir = new File(dirStr); String[] javacArgs = new String[] { "-d", dirStr, new File(dir, srcFileName).getAbsolutePath() }; System.out.println("Compiling ..."); Main.compile(javacArgs); /* *load the class and the static block of class T will be executed */ URL url = new URL("file", null, dirStr+"/"); URL[] arr = new URL[]{url}; URLClassLoader loader = new URLClassLoader(arr, Thread.currentThread().getContextClassLoader()); Class.forName("T", true, loader);
config file T.java instead .xml
Code:public class T { static { /* * do some configuration */ System.out.println("OOOKKK"); } }


Reply With Quote
), one of the dynamic script languages Spring supports might be a better idea than Java itself.
