Saturday, October 06, 2007

Easy portlet development and reduced roundtrip with the updated Struts 2 portlet archetype

The entry has been updated to reflect the new 2.1.1-SNAPSHOT release

I have just deployed an updated version of the Struts 2 portlet archetype, which is based on Struts 2.1.1. The archetype also includes the jetty-pluto integration which should reduce the roundtrip from development to testing and running quite a lot.

To create a basic Struts 2 portlet with the archetype, run the command

mvn archetype:create
-DgroupId=<groupId>
-DartifactId=<artifactId>
-DarchetypeGroupId=org.apache.struts
-DarchetypeArtifactId=struts2-archetype-portlet
-DarchetypeVersion=2.1.1-SNAPSHOT
-DremoteRepositories=
http://people.apache.org/repo/m2-snapshot-repository

(all on one line)

Just replace <groupId> and <artifactId> with your real groupId and artifactId. Now you can just type mvn jetty:run -P pluto-embedded to run the portlet in pluto. The pluto-embedded profile does the magic of setting up the integration between the maven-jetty-plugin and pluto. To test it, just open a browser and point it to http://localhost:8080/<artifactId>/pluto/index.jsp

I have also included a class called JettyPlutoLauncher (you might recognize it from a previous entry) in the test sources of the generated project. It is simply a class with a main method that can be used to launch the portlet from your IDE. To use it with eclipse simply type mvn eclipse:eclipse -P pluto-embedded, import the project in Eclipse, and select to run the JettyPlutoLauncher class. Then open a browser to the same URL as described above.

This will hopefully get you up and running with Struts 2 portlet development pretty quick!

11 comments:

Anonymous said...

after following your steps, i get java.lang.NoClassDefFoundError: com.opensymphony.xwork2.util.logging.LoggerFactory

where can i get this dependency, and does a pom need to be updated?

Nils-Helge Garli Hegvik said...

Hi!

Thanks for the feedback.

Struts 2.1 and XWork 2.1 has not been officially released yet, so work is being done. Aparently, there has been a change somewhere that break things since this entry was written. Both Struts 2.1 and XWork 2.1 will have releases very soon, so I'll make sure to update the archetype and this example. Until then, you can check out the XWork 2 and Struts 2 trunks (http://www.opensymphony.com/xwork/cvs.action, http://struts.apache.org/dev/builds.html) to build and install the latest code and see if it works.

Anonymous said...

thanks for the quick response! i was able to download and install the sources ... unfortunately, i had to skip the test cases b/c many were failing ... oh well, at least your handy development tool works now! thanks for the work

Anonymous said...

as a follow up, i have built and tested my portlet, and now i want to deploy it to a Websphere App Server. Can you give any more information about the changes from 2.0.x to 2.1 in terms of portlet / web.xml configuration changes? i see that the PreparatorServlet but have not been able to find documentation on the usage of its replacements

Nils-Helge Garli Hegvik said...

The PreparatorServlet and the ServletContextHolderListener. The related issue can be found here

Other than that, you can find all the changes here

The major change is that the portlet support has been refactored into a plugin.

Bakann DY said...

It does not work with Jahia Portal which works with JSR168.

Nils-Helge Garli Hegvik said...

Hi!

The Struts 2 Portlet framework is 100% JSR168 compliant. However, deployment of the portlet application can vary from server to server. If you have problems getting it to run in a specific portlet container, I suggest that you try the Struts 2 user mailing list, or register an issue at https://issues.apache.org/struts/secure/Dashboard.jspa with the details of your problem.

Bakann DY said...

Thank you for your quick answer. I will post an issue.

For your information, when I deploy into Jahia Portal, I get a message :"Failed to load portlet org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher: javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found".

With OpenPortal Portlet Container, it runs well.

Andrea said...

At the moment the the struts2 portlet archetype is no longer available at http://people.apache.org/repo/m2-snapshot-repository. Could you publish it in some other repository ?

Thanks

Bakann DY said...

Do you know how tu use annotation validation within struts2 portlets?

I did tutorials for struts2 webapps. But there's no example for struts2 portlets.

Yilmaz Ay said...

Hi All,
I am trying to create a simple Struts 2 web application. I downloaded the latest Struts2 package (2.1.8...)
And i put all libs (jars in the lib folder) into my classpath.
my simple sample application can compile, but when i want to run it throws java.lang.NoClassDefFoundError: Lcom/opensymphony/xwork2/util/logging/Logger error.

I am pretty sure this file does exist and it is my classpath, but it keeps throwing this error.
Does anyone have any idea?