Friday, May 27, 2005

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.

22 comments:

Suzan Foster said...

Tnx! You just saved me a wasted day :)

Anonymous said...

Very sweet!!! Tnx for the help!

Ian said...

You're welcome both.
-Ian

Richard said...

I could have used this information 3 hours ago. It's amazing what you can achieve with the right google search terms. Thanks a lot :)

sven said...

Thanks for help. I had the same problem with tomcat and axis in eclipse and it works now. (Must be an eclipse problem...)

Anonymous said...

You could use the JRE tab and choose/create a JRE that is a true JDK and hence already includes tools.jar.

Anonymous said...

Thanks. This solved the problem I have with "ANT" in "Eclipse 3.1" by adding it to the "ClassPath" tab in the "External Tools".

Anonymous said...

Many thanks guys, you probably saved me a day!
Olivier

morgoth7 said...

Many thanks, now on to the next error! That's progress.

CreepY said...

Tnx :*

Anonymous said...

From a Brazilian Developer "Obrigado" (that means "thanks") =))

Now I can use my freetime to play soccer. ;)

Anonymous said...

This worked for running Tomcat as a service on XP! I just used tomcat5w.exe in the bin dir of my tomcat inst and added it to the classpath on the Java tab. Tnx! Why isn't this a standard config or easier to find? The ability to use JSPs with Tomcat is pretty standard...

Martin said...

Your a legend mate. You just saved me alot of time.

Edoardo said...

Grazie mille=Thanks a lot :)

Was starting to seek for rocket science solution but then ... google it!

Immo Huneke said...

Brilliant! It worked for me (using Tomcat and Axis)

Anonymous said...

"Merci" (Thanks in French :) )

Darryl Johnstone said...

Am I ever glad I found that tip! I was searching all over, and messing with my classpath, and any other shot in the dark. This trick fixed me right up... who would've known? How would you know?

roli said...

One can resolve this issue in tomcat - eclipse by going to windows-->preferences-->tomcat-->jvmsettings

over here add the tools.jar found in your java_home/lib directory to (Classpath...before generated classpath) by browsing to the tools.jar file.

Ryan said...

dude... this is seriously the second time I stumbled across this problem, couldn't figure it out, turned to google, and wound up here for the solution. thanks a million.

Anonymous said...

Yup, just ran into this problem, and your solution saved me hours of hunting! Thanks!!!

Anonymous said...

This page was the first result after a google-search. You saved me, thanks :) !

Anonymous said...

Thanks - saved me alot of frustration! - Paul