Skip to main content

ToolProvider.getSystemJavaCompiler() always returning null

3 replies [Last post]
Joined: 2006-11-06

When I call ToolProvider.getSystemJavaCompiler() on our development system it works correctly. However, in production it is returning a null. It is being called from tomcat and both systems are using the jdk as JAVA_HOME. We are running 1.6u10. Does anyone have any idea as to why this is happening?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2009-01-24

In my case, on a windows PC, setting %JAVA_HOME%\bin at the start of PATH system env variable did the trick.


Joined: 2007-04-17

Does the production computer have the JDK (with the compiler) installed or just the JRE? Possible you need to start Tomcat from the JDK as well (jdk/bin/java.exe or similar).

Joined: 2004-05-06

Firstly, try printing the value of the system property 'java.home' from your Tomcat app just in case Tomcat is ignoring JAVA_HOME environment variable and using something else.

From looking at the source of ToolProvider, it seems to:
- first tries doing a Class.forName on with the caller's classloader. If tools.jar is on the classpath this shouldn't result in problems unless Tomcat is doing some classloader trickery to prevent this class from being found from a webapp's classloader.
- If the previous step fails, it looks at the java.home system property and tries to find tools.jar within that directory, going to parent if it ends with 'jre'. It then tries to make a classloader for this JAR and load the compiler from there.

Not sure if this helps or if I've got the above exactly right. But looks like java.home system property plays a central part in the discovery process. Try checking that first.