Thursday, August 21, 2008

JBoss Portlet support in Eclipse

JBoss Tools 3.0.0 Alpha1 has been released with initial support for portlets (including JSF and Seam portlets).

Two warning, first it is Alpha with all it means. Second one, the blog entry looks long and complicated. In fact i included many screenshots so that people who don't want to try can have a good overview of how it works. It's very simple for anyone a bit familiar with Eclipse.

First we need Eclipse Ganymede, JBoss Tools 3.0.0 Alpha1 and a version of JBoss Portal (bundle if you are looking for simplicity, and 2.7 if you want a Portlet 2.0).

Extract Eclipse and JBoss Tools, you should get a unique "eclipse" directory.
Extract JBoss Portal

$ tar zxvf ~/Download/eclipse-jee-ganymede-linux-gtk.tar.gz
$ unzip ~/Download/JBossTools-3.0.0.Alpha1-ALL-linux-gtk.zip
$ unzip ~/Download/jboss-portal-2.7.0.B1-bundled.zip

Now you should have an "eclipse" directory. Let's go in it and start Eclipse.
Once started go to the workbench and do File>New>Dynamic Web Project.

You can fill-in the name for your project.

And create a new "Target Runtime" such as on the following screenshot:

And point it to the location of your JBoss AS + Portal installation:
Now don't forget to set a Portlet Project configuration (Portlet 1.0 or 2.0)

And click on Finish.
Our base project is done, now let's add a portet into it.

Choose File>New>Other (or Ctrl+N) then select one of the JBoss Web Tools>Portlet wizard.

We'll pick Java Portlet for this blog. Fill in the Java Package and the class name and click Next.

On this other screen you will be able to set the display name of the portlet, a title, a description, the supported modes and init parameters.

On the next screen you can define which methods you want to override from GenericPortlet.

The last screen let you build JBoss Portal specific descriptors to create an instance during the deployment and place it directly on the portal.
Now that it is done, all the requires files are part of the Eclipse explorer and are ready to be built and deployed.
Now right click on the project and do Run As>Run On Server and accept the default. It will deploy the portlet web application and start JBoss AS.
(Little glitch, once started it will open the browser on http://localhost:8080/foobar, use http://localhost:8080/portal and you will see your portlet:

And voila ! From here you have access to all the other features of JBoss Tools.

Thanks Snjezana for the hard work !

13 comments:

Unknown said...

I have a problem. I have download eclipse 3.4 with jboss tool 3.0 alpha1 on mac and when i load a new portlet's example(hello world) there isn't a declaration of javax.portlet. can you help me? please

Unknown said...

Hy

I've got the same problem.

when I create a new project, I don't have "Portlet Project v X.X" in configuration (see http://4.bp.blogspot.com/_qfEbDTOhbrs/SK3Gv_MFWPI/AAAAAAAAAT4/50RFxBRAZ2M/s1600-h/DynamicWebProject.png )

any solutions?

thanks in advance

Sidydrum said...

In eclipse, when you create/configure a new server to publish to, you have to choose
"JBoss, a division of read hat" runtime instead of "JBoss"
server kind.
This solved my problem to the "portlet project" not being visible.

(It seems javax.portlet is not part of the standard libraries in the "JBoss" server kind)

Unknown said...

well, i don't remember what i selected, probably "jboss a division of read hat", but i solved my probleme by installing jboss tools 3.0.CR1 instead of CR2.

perhaps a bug?

K K said...

all got problem.. include me.. can u re explain in ur tutorial please

theholyjava said...

How to create the necessary Portlet Project v2.0 configuration:

I too haven't seen anything but JBoss Seam Portlet Project v2.0 in the list of possible configurations.

You can easily create your custom configuration from the new project wizard by clicking Modify... - you will need to check there JBoss Portlets > JBoss Core Portlet. (You should have also Java, Dynamic Web Module.)

A project must have this facet to work correctly, e.g. to display the portlet when you access http://localhost:8080/portal .

Unknown said...

Ok, you can custom your configuration, but for me, there was nothing about JBoss Core Portlet in the available faces.

Installing jBoss Tools 3 CR1 instead of CR2 solved my problem!

theholyjava said...

That's possible, I have CR1.

I've also downloaded JBoss Developer Studio 2.0.0CR2 and tried it there, surprisingly there was no portlet-related facet at all. So you might be right that this is a bug in the latest jboss tools. Maybe you should open a bug report.

Kobe said...

I'm also having the problem seeing Portlet Project v x.x show up. I can't find a download for jboss tools 3.0.CR1. Does anyone know where I can get it, instructions on how to install it in place of 3.0 GA? I'm new to Java development

Lets be a team said...

Well, it has worked for me, but not exactly in a way it has been mentioned here.

I created a dynamic web project, since i do not see any Portlet verx.x.x.x

After the project is created, change it properties to include Jboss Portlet.

Then follow as mentioned, add file -> other -> Jboss Portlet ...

And it works smoothly.

Sorry guys, am no java expert, this is my first attempt to work with eclipse and Jboss

Vuong Nguyen said...

that funny!
i created project portal nomaly but when i add new portlet it only add to file portlet instance and portlet.xml.No java file portlet created.
Please help me. why

Dominik Pospisil said...

This was a bug in JBoss Portlet tools. Which version of Tools you are using? See https://jira.jboss.org/jira/browse/JBIDE-5402

The_Cjay said...

What the... There is not javax.portlet package and GenericPortlet class available in my dynamic web project (Eclipse galileo 3.5.1 with jboss tools 3.0.3 GA). But.. there is not portlet.jar in server "lib/" directories (jboss-portal-2.7.2-bundled). What I have to do and what I'm doing wrong?