Tomcat J2EE bug tracking
Bugzero one-for-all bug tracking manager
 
Q: Tomcat unable to find a javac compiler;
   com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK

A: The complete stack trace is:

org.apache.jasper.JasperException: Unable to compile class for JSP
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause 

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:106)
org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:935)
org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



The cause:

This error is a result that Tomcat can't find the %JAVA_HOME%/lib/tools.jar. 


What to check:

Make sure the classpath Tomcat uses is correct, partcularly it should include tools.jar
Add a line like
echo CLASSPATH=%CLASSPATH%
in either setclasspath.bat or catalina.bat, and start Tomcat with 
catalina.bat run
and see what it prints out.


Solution:

If you installed either JDK or Tomcat in a path that include space, like
'Program Files', then, you might want to re-install to it to something
like c:\jdk1.5.0_20 or c:\apache-tomcat-5.0.28.

If you have installed NT service for Tomcat and then upgraded JDK, you will
need re-install the service.

Recommandation:

If you follow the following steps, you'll never have a problem as above:

0. un-install both JDK and Tomcat.
   Download jdk1.5 or 1.6; and Tomcat 5.5 or 6.0
1. Install JDK first, and install it under c:\jdk1.xxx without space.
   and then add/edit env JAVA_HOME to c:\jdk1.xxx, 
   and edit env path to add %JAVA_HOME/bin; in front.
2. Install Tomcat (basicall you just need unzip it) under c:\
   so you will have something like c:\apache-tomcat-5.xxx,
   again, no space in the path.
3. That's it.


* Reference brought to you by Bugzero, it's more than just bug tracking software!

Home - FAQs