Compiler API and Tomcat
Hi!
I am using the new compiler api to compile dynamically generated classes.
To get the compiler tool i call:
JavaCompiler compilerTool = ToolProvider.getSystemJavaCompiler();
when I run this from eclipse with the integrated tomcat everyhing works fine but if I deploy the application on the external tomcat i get a null pointer exception because getSystemJavaCompiler(); always returns null.
Somebody got an idea why?
# 1
Perhaps the external tomcat is running on JRE or does not allow ToolProvider to create a class loader for loading tools.jar. In JDK 7 I have added some logging facilities to help debug such situations. However, they are not yet available for JDK 6.
# 3
sigh, NEVER put ANYTHING in the jre/lib/ext directory.
It's a bad thing that it's even there, as it causes systems to become mutually incompatible and to behave unpredictably when different versions of classes are needed/present.
The compiler API (and others) that depend on the local filesystem are disallowed by application servers for security reasons.
You've just given access to every cracker in the world to your system by allowing them to compile and run code on your machine with root privileges. Your boss will thank you.