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:

Anonymous Suzan Foster said...

Tnx! You just saved me a wasted day :)

10 June, 2005 11:38  
Anonymous Anonymous said...

Very sweet!!! Tnx for the help!

15 June, 2005 19:52  
Blogger Ian said...

You're welcome both.
-Ian

23 June, 2005 09:41  
Anonymous 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 :)

30 June, 2005 15:59  
Anonymous 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...)

31 August, 2005 08:29  
Anonymous Anonymous said...

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

16 November, 2005 22:09  
Anonymous 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".

09 December, 2005 07:31  
Anonymous Anonymous said...

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

06 January, 2006 20:12  
Anonymous morgoth7 said...

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

06 February, 2006 16:08  
Anonymous CreepY said...

Tnx :*

24 March, 2006 03:57  
Anonymous Anonymous said...

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

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

26 April, 2006 19:44  
Anonymous 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...

07 May, 2006 01:57  
Blogger Martin said...

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

07 June, 2006 08:06  
Anonymous Edoardo said...

Grazie mille=Thanks a lot :)

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

01 July, 2006 23:35  
Anonymous Immo Huneke said...

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

08 August, 2006 17:08  
Anonymous Anonymous said...

"Merci" (Thanks in French :) )

20 August, 2006 13:51  
Anonymous 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?

23 August, 2006 20:43  
Blogger 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.

11 September, 2006 10:33  
Anonymous 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.

20 September, 2006 03:08  
Anonymous Anonymous said...

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

10 November, 2006 01:12  
Anonymous Anonymous said...

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

18 November, 2006 11:28  
Anonymous Anonymous said...

Thanks - saved me alot of frustration! - Paul

19 December, 2006 17:41  

<< Home