Wednesday, March 28, 2007

Running Portlets on Pluto from within Eclipse

The Pluto team recently released version 1.1.0 and as part of that release they include a very useful Pluto + Tomcat bundle that makes it very easy to get started. So I've been playing around with this and trying to figure out how to get it to work with Eclipse + WTP, and initially I ran into some issues. By default, WTP wants to take your application server and copy its files to a temporary location in which to deploy your webapp. However, this is fairly disastrous for portlet development because WTP doesn't copy everything and leaves behind important stuff like shared/lib, the portal webapp, etc. So I was trying to figure out what was left behind and manually copying the missing bits into the temporary location... aargh! And then I discovered a nice little feature of WTP. There is this "Run modules directly from the workspace" checkbox in the server settings for your app server, and unchecking this has the effect that Eclipse will deploy your web applications to the location of your app server and not some temporary location! So anyways, here are my notes on how to get this to work.

First, you need to register the Pluto 1.1/Tomcat 5.5.20 bundle with Eclipse as a Tomcat 5.5 server. Select File > New > Other and select Server, then click Next (or, if in the J2EE perspective, right click in the Servers View and select New > Server). Select a server type of "Tomcat v5.5", and click Next. Name it whatever you like, I call mine "Apache Tomcat v5.5 - Pluto". For "Tomcat installation directory:" browse to the location of where you installed the pluto bundle.




Click Finish. Now, we need to modify our Server definition for pluto just a bit, so go to the Servers view (if you don't have it, just switch to the J2EE perspective, or add the view with Window > Show View > Other..., then select Servers). Double click on your Pluto server defined there. Uncheck the "Run modules directly from the workspace" checkbox. We want Eclipse to run Pluto from the location of the pluto-bundle, so that it picks up the pluto webapp, shared/lib, and other bits that are needed because we are working with portlets.




Now, in order to run your portlet in Pluto from within Eclipse using WTP, you need to have your web.xml "pluto-ified". The Pluto guys have an Ant task called "assemble" which can do this for you, that's what I use. Just have it update your web.xml file (probably want to make a backup first). I've been working with a hello-world JSF Facelets sample portlet recently, here's how I get it running in Pluto:

Now we just need to get our application running on Pluto/Tomcat as before (right click on the Project, select Run As > Run on Server). The difference this time is that we will access our application through Pluto. In your web browser, go to http://localhost:8080/pluto. Login as user pluto, password pluto. In the upper left hand corner there is a label called "Navigation:". Mouse over this label to get a popup menu. Then select Pluto Admin from this list. Under Pluto Pages, select Pluto Admin from the drop down list. Then under Portlet Applications, select hello-world-jsf-facelets in the first drop down, and then in the second drop down select HelloWorldSamplePortlet, and click Add Portlet.



Now, the portlet should be there at the bottom of the page.



Note that the portlet pages configuration doesn't persist across restarts of the Pluto server. Consult the Pluto documentation if you want to persist the portal pages layout and configuration.

Now that our portlet is deployed to Pluto from within Eclipse, we can develop our portlet and have the changes immediately reflected in Pluto!

4 comments:

Ton said...

I've followed the steps outlined, but I'm unable to compile the AssembleTask Ant task. The compile is missing (among others) org.apache.pluto.util.assemble.AssemblerConfig and org.apache.pluto.util.assemble.AssemblerFactory
and I'm unable to locate a jarfile in my Pluto distribution that contains them. I'm using the Pluto 1.1.2 bin-complete distribution.
Is it possible to add a pointer to the blog entry about getting the Ant task running? (I'm familiar with Ant and custom tasks btw, having written custom Ant tasks myself; I'm just confused about how to get the thing compiling). TIA.

Ton said...

OK, I have the Ant task compiling:
- the link to the Pluto util project http://portals.apache.org/pluto/pluto-util/index.html is dead, so I downloaded the pluto-util source. This, of course, had dependencies on various other projects (jakarta commons and junit) but once I downloaded and added those, and added util as a project dependency to the ant task project the ant task compiled.

I have yet to deploy a first portlet to pluto, though - that will have to wait for another day, as its bedtime for me!

Marcus Christie said...

I started from the Pluto 1.1 sample portlet.

And by the way, if you are using Maven2, transitive dependencies come to your rescue here. The is what I have as the dependency in my pom.xml file:

<!-- Pluto ant tasks -->
<dependency>
<groupId>org.apache.pluto</groupId>
<artifactId>pluto-ant-tasks</artifactId>
<version>1.1.0</version>
</dependency>

Lee said...

I'm now working for a new company and after a few years of developing portlets on and off again, I'm looking to replicate the dev environment i had with JDeveloper using eclipse, tomcat, to roll out as the standardized dev environment for a couple hundred developers that will be moving their apps into our portal in the coming year. This is to say i want to be able to:
1. create portlets and all the little files with them via a wizard
2. edit the portlets in eclipse
3. deploy them with a button click into a provider accessible from our dev portal so people can see their apps on a real and full portal page as they develop.

This is exactly what i had with JDev, but the developers here are all used to eclipse, and want to stick with tomcat as their app server even though we're using the oracle portal. Any suggestions for a setup?

-Lee