Saturday, 15. August 2009
Jetty and the NoSuchMethodError
Jetty is a small servlet engine you can embed in your application. For my first experiment I started with a simple program to use it as HTML server:
public final class Runner {

    private final Server jetty;

    public Runner() {
        jetty = new Server(4040);
    }

    public void start() throws Exception {
        jetty.setHandler(new WebAppContext("src/main/webapp", "/"));
        jetty.start();
    }

    public static void main(String[] args) throws Exception {
        ClasspathMonitor.addAsShutdownHook();
        Runner runner = new Runner();
        runner.start();
    }

}

I have created a simple HTML page which is located in the directory src/main/webapp. After running this little Runner class from Eclipse I could see the HTML page under http://localhost:4040/.

Now I want more - I want to use it as JSP engine. Before I did a small test to use it as servlet engine which was successful (I created only a small web.xml with an InitServlet). To use Jetty as JSP environment you must include some libraries which are listed in Embedding+Jetty (e.g. the Jasper libraries).

I put the needed libraries in my classpath, created a simple JSP and started Jetty again. When I access the JSP page I got a HTTP ERROR 500 and the following stacktrace:
org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer.(Lorg/eclipse/jdt/internal/compiler/env/IBinaryType;)V

Caused by:

java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer.(Lorg/eclipse/jdt/internal/compiler/env/IBinaryType;)V
	at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:214)
	at org.apache.jasper.compiler.JDTCompiler$1.findType(JDTCompiler.java:183)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:119)
	at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:178)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2149)
	...
What the hell is the problem here? My first suspicion was that it could be a classpath problem. But how can I confirm it?

to be continued...

... comment