views:

1682

answers:

2

I'm trying to set up Eclipse to run and deploy my projects to a Jetty 7 server (the oldest version available from http://download.eclipse.org/jetty/). I've downloaded Jetty 7 and unpacked it, and I've installed the Jetty plugin from the available server adapters list, but when I try to configure a new Jetty server, the server type list only contains "Jetty 6". If I use this and point it at my server runtime, when I try to start it I get the following error:

java.lang.NoClassDefFoundError: org/mortbay/start/Main
Caused by: java.lang.ClassNotFoundException: org.mortbay.start.Main
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" 

I'm guessing I need a different adaptor to start Jetty 7, but I have no idea where to find it.

+1  A: 

The problem is that the package name changed with the migration to Eclipse, and the Jetty folks are still busy.

Your easiest option is to download Jetty 6 from Codehaus (http://dist.codehaus.org/jetty/), unpack it somewhere and use the Jetty 6 adapter.

Thorbjørn Ravn Andersen
Kind-of ironic that the move to being an official eclipse project has made it *harder* to use Jetty with eclipse, but it does appear to be the case. Oh well, back to v6 I guess. :(
+5  A: 

Better than using the WTP adapters I prefer to use an embedded jetty. I just create a regular java project, let's call "embedded-jetty". I make the original webapp project a requirement to this project in the Projects section of the Java Build Path of the project properties. Than I create a class that start a jetty instance like this:

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;

public class JettyServer {
 public static void main(String[] args) {
  Server server = new Server(8080);

  WebAppContext context = new WebAppContext();
  context.setResourceBase("../webapp-project/WebContent");
  context.setDescriptor("../webapp-project/WebContent/WEB-INF/web.xml");
  context.setContextPath("/");
  context.setParentLoaderPriority(true);
  server.setHandler(context);

  try {
   server.start();
   server.join();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

On the embedded-jetty project I create a "lib" folder and copy all the libs from the jetty/lib folder, then I add the libs on the Libraries of the project properties.

Running and debugging the jetty embedded works great for me, the jsp and class reloading works like a charm

Dimas Kotvan
Interesting idea. I used to do something similar to this, but it ended up with my web apps being dependent on jetty, which is something I want to avoid. Your approach doesn't seem to have this problem, though. Thanks.