Monday, August 27, 2007

Launching and debugging Portlets from Eclipse with Jetty and Pluto

Last time I showed how you can combine Jetty, Pluto and JWebUnit (or any other web testing framework for that matter) to easily write integration tests for your portlets. As a short follow up, I'll show you how to use the same setup to create a simple "Launcher" to get your portlets up and running quickly from Eclipse (but it can easily be modified to work in your favorite IDE).

The first thing to do is to add the usual dependencies to your pom.xml file (assuming you're using Maven 2 to build your portlet project. If not, add the dependencies to your classpath manually):

Update: The maven-jetty-pluto-embedded artifact is available in the Maven 2 repositories.


(if you want to know what the maven-jetty-pluto-embedded artifact is, read this). Note that if you have any other dependencies that either directly or indirectly has a dependency to a different version of the servlet api that Jetty 6.1.5 is using (like commons-logging), you need to explicitly exclude this dependency, adding the following snippet inside the dependency:


If you have not already done so, run mvn eclipse:eclipse to add the dependencies to your Eclipse project. Next, create a new class called JettyPlutoLauncher (I put it in my src/test/java folder). We'll add a main method to this class, doing the exact same as the setUp() method of our base integration test described in the previous entry:

import org.apache.pluto.core.PortletServlet;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.webapp.WebAppContext;

public class JettyPlutoLauncher {
public static void main(String[] args) throws Exception {
System.setProperty("org.apache.pluto.embedded.portletId", "portletId");
Server server = new Server(8080);
WebAppContext webapp = new WebAppContext("src/main/webapp", "/contextRoot");
ServletHolder portletServlet = new ServletHolder(new PortletServlet());
portletServlet.setInitParameter("portlet-name", "portletId");
webapp.addServlet(portletServlet, "/PlutoInvoker/portletId");

Replace all occurrences of portletId with the actual id of the portlet to run, and contextRoot with the context root you want for your application.

That's it. Now you can simply select your class and do "Run As - Java Application" to run, or "Debug As - Java Application" to do step by step debugging your portlet!


Software Wikipedia said...

Hi, Would you be interested to exchange link with my blog at
mail me at if you are interested.

Prabhat Jha said...

I wrote a similar blog at