brush clojure

Wednesday, June 11, 2008

Generating IBM RSA Websphere projects with Maven

Rational Software Architect (RSA) may not be the best development environment, but when it comes to WAS-integrated IDEs, there are not that many choices. RSA is the familiar Eclipse packaged together with some plugins, which provide integration with Websphere. Starting with a Websphere Web application with RSA is easy - just choose the right project type and you can immediately run the application in Websphere from the IDE.

If you are working with Maven, however, there are very good reasons why you will not want to create any projects drom RSA. All of them boil down to the DRY principle - Don't Repeat Yourself. The Maven POM files already describe your projects and dependencies, why would you want to do this second time in RSA? You are going to make your release builds (and continuous integration) with Maven anyway, and any RSA project changes you make have no impact on the build. You may end up bulding something different than what you develop. Maintaining dependencies at two places - in maven poms and in your RSA project is not good, and Maven is much better in the dependency stuff.

Besides, why lock to RSA? If you can generate the IDE files for RSA/Websphere, so you can for Eclipse/Tomcat, for example.

The Maven Eclipse plugin generates the needed IDE files. The point is you want to be able to use them directly in RSA. It took me some time to get the POMs right, so I thought it is worth sharing.

Typically in a Websphere app, you have an EAR project, a Web project and several JAR projects. In this example, I start with 3 projects: ERA, WAR, JAR. Define them in the parent POM:



<modules>
<module>app-jar</module>
<module>app-web</module>
<module>app-ear</module>
<modules>


Further in the parent POM, declare you are using java 5.0:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>


N.B. Define 1.5 and not 5.0, this was fatal for my RSA installation!

There's nothing special about the JAR project, the generated eclipse project is fine. For the Web project, few more settings are essential. Assuming you have a maven webapp archetype project, include the following under build/plugins in the project's pom:


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
<wtpContextName>myapp</wtpContextName>
<additionalProjectFacets>
<jst.java>5.0</jst.java>
<com.ibm.websphere.extended.web>6.1</com.ibm.websphere.extended.web>
<com.ibm.websphere.coexistence.web>6.1</com.ibm.websphere.coexistence.web>
</additionalProjectFacets>
</configuration>
</plugin>


The generated project will be a Dynamic Java project, and RSA wil recognise src/main/webapp as the web root folder. The web context name is also define in the plugin settings.

Similar setting are needed for the EAR POM:



<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<wtpversion>1.5</wtpversion>
<additionalProjectFacets>
<jst.ear>1.4</jst.ear>
<com.ibm.websphere.extended.web>
6.1
</com.ibm.websphere.extended.web>
<com.ibm.websphere.coexistence.web>
6.1
</com.ibm.websphere.coexistence.web>
</additionalProjectFacets>
</configuration>
</plugin>


The generated project is recognized by RSA as an EAR project. Of course, you need a correct application.xml in src/main/application/META-INF. This project doesn't contain any code, but is still usefull for maven, as it will build the release EAR.

Once that all is done, go the the project root and run mvn eclipse:eclipse with any extra options you may need. Import the generated projects in RSA (File/Import/Existing projects int workspace). The resulting file structure is the well known maven webapp structure:



To run the application from RSA, drag the EAR project to 'Web Sphere Application Sever' in the Servers view and start te server.

There is one issue that has not been addressed here - how do you get all those WAS-specific IBM files. Update follows.

Profiles

It's a good idea to set all those settings in maven under a profile. For the next environment, add a new profile.

Hiccups

Yes, they are very present:
- Go to the app-web project, Properties, J2EE dependencies, Web libraries - all library dependencies are there but not the project dependency on app-dom, while it obviously should be. Add it. I couldn't find a solution for this, tips about it will be very appreciated.
- Make sure that the web module element in application.xml has no id attribute. The id runs out of sync each time project files are generated.
- Sadly enough, after fiddling with application and server deployment configuration, now and then I just have to restart RSA to make the web application running.