In a project that makes heavy use of reflection to select classes based on environment, is there a way to determine what libraries to include in the build? At the moment, taking a library out of the project is a gamble, but sticking with the current plan of "include everything, it's the only way to be sure" makes the whole thing bloated and unwieldy.
+1
A:
You can use JavaAssist lib to include new classpaths or modify classes at runtime.
You can register a directory name as the class search path. For example, the following code adds a directory /usr/local/javalib to the search path:
ClassPool pool = ClassPool.getDefault();
pool.insertClassPath("/usr/local/javalib");
The search path that the users can add is not only a directory but also a URL:
ClassPool pool = ClassPool.getDefault();
ClassPath cp = new URLClassPath("www.javassist.org", 80, "/java/", "org.javassist.");
pool.insertClassPath(cp);
Telcontar
2010-08-13 07:38:22
+1
A:
Unfortunately there isn't as this would be difficult for classes loaded dynamically, especially using factories where class name is passed as Strings.
If you jvm supports the -Xcomp and -Xbatch
options along with the -XX:CompileThreshold
, you can use it in your development and testing environment. It will increase your startup time though.
These options will just make your job easier but you will still probably have to test you thoroughly.
naikus
2010-08-13 07:48:40