Launch Jetty from Eclipse - solving "Unable to find a javac compiler"
I’ve not used Jetty for a little while, and in the interim I’ve upgraded my computer and switched to Linux. Needless to say, when I came to running Jetty to do some web service work this morning, it broke. Specifically, the symptom was that when I launched Jetty from Eclipse, using the Jetty launcher plugin, Axis would fail with a nasty error message:
HTTP ERROR: 500 Unable to compile class for JSP RequestURI=/axis/index.jsp
The problem is that the front page for Axis has changed since I last used it: it’s now internationalized, which is a good thing, but it uses JSP’s to do the internationalizing. JSP’s are compiled dynamically, hence the need for a compiler. The HTTP error is accompanied by a stacktrace:
2005-05-27 21:35:54,421 ERROR \[SocketListener0-1\] compiler.Compiler (Compiler.java:412) - Javac exception
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
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:929)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:758)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:407)
.....
Do not listen to the tricksy error message. He is lying! Don’t waste hours
messing with your JAVA_HOME
setting, wondering if the problem is related to
using Java SDK 1.50 or 1.4.2, and switching back and forth between like a thing
posessed. No, the simple answer is to add tools.jar (found in the lib directory
of your Java SDK) to the classpath given to the Jetty instance. There’s a tab
to set the Jetty instance’s classpath as part of the Jetty Launcher. Easy when
you know how.
Update Dec 2006: Thanks for the nice comments and useful suggestions folks. I’ve now closed this entry to further comments.