Thursday, March 23, 2006

J2EE with Maven 2 + WTP

Today I decided to revisit WTP, since they came out with a new version 1.0.1, I thought I'd give it the good old college try again. This time blog the experience too. Along with this, I decided to take maven2 out for a spin again with J2EE projects. I will avoid trying to be mean like the BileBlog, because I don't think there is a need to. As expected, Maven 2 is lacking in documentation on how to set up a J2EE project with Eclipse. Granted they need to get it working first which they might've but I am not looking at the SVN version of their project, just the 2.0.2 that was released along with the plugins that come with it. If you are going to attempt something new with Maven 2, I suggest you have three things open:

  1. CGI:IRC client pointing to #maven
  2. Maven's JIRA
  3. Google
First off, the eclipse plugin that comes with Maven release doesn't work correctly so you should at least try to get the latest release version of the plugin by adding to your POM. It does not autoupdate either with the -up or -cpu command paramter of mvn as I noted in MECLIPSE-82:
<build>
 <plugins>
   <plugin>
     <groupid>org.apache.maven.plugins</groupid>
     <artifactid>maven-eclipse-plugin</artifactid>
     <version>2.1</version>
     <configuration>
       <workspace>${basedir}</workspace>
       <!--<downloadsources>true</downloadsources>-->
     </configuration>
   </plugin>
 </plugins>
 ...
</build>
This will ensure that you get the 2.1 release of the eclipse plugin. Now that's on my root project POM. I plan to create a multiproject Maven setup so one project for WAR, domain objects, EAR and maybe one for EJB later. So I create additional projects and POMs for the sub project, for now I only did a war, a jar, and an ear. No EJBs yet. In the WAR pom.xml make sure you add the following in the build section in order to create the proper Eclipse WTP meta data.
<plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-eclipse-plugin</artifactId>
 <configuration>
   <wtpversion>1.0</wtpversion>
 </configuration>
</plugin>
I also created a simple JSP to test if everything works. Using Vincent's instructions with Cargo and a slight tweak that is to change dir to home. I also think ${basedir}/src/main/webapp can be changed to something else like ${maven.war.src.webapp} or something, but I haven't found it yet. Anyway you then just type in mvn cargo:start to get things going. Then go to the browser and go to http://localhost:8080/webapp/ivt.jsp. Cool so I can run things on Cargo environment with Jetty. I have to see how to do it with Geronimo later. Now, I do a mvn eclipse:eclipse on the root project (btw, it has the packing of pom. As expected it does not generate any .project files for the root project, but generates them for the subprojects. However, it does seem to not know how to handle ear packaged projects and treats it like a standard Java project. The others went correctly. I had trouble earlier with eclipse:add-maven-repo and I haven't really pushed forward with it much. For now I added the M2_REPO variable to my pristene Eclipse workspace built from wtp-all-in-one-sdk-R-1.0.1-200602171228-win32.zip. Anyway, I just imported the projects and everything went well for the most part (the EAR project is busted as it is treated like a Java project). However everything else is okay. Now using Geronimo devtools and the devworks article as a guideline to use this the Geronimo Eclipse plugin, I got everything installed. Quite nice. Just had to point it to a freshly downloaded Geronimo installation directory. Tried to start the server. Works beautifully and I can access the admin console. However.... I tried to install my WAR (since the EAR was not available) no dice when I tried to load it. And when I checked the console, it wasn't even there. So I tried Tomcat 5.5 which I also had installed. Everything works. However, since I want to build an EAR eventually this will not do. Then I thought what if I used the other Geronimo that uses tomcat rather than Jetty. Start up time was noticibly slower. However, no luck still with my webapp. So for the time being I think I am stuck with Tomcat. Or use RAD 6.0 which has an integrated test environment for WebSphere.

7 comments:

Archimedes Trajano said...

Rather than letting Eclipse's WTP handle things I decided to use the update URL http://geronimo.apache.org/devtools and see what I can find.

I found something called installableruntimes and decided to download the Jetty one. Maybe that runtime would work rather than the one I took from the Apache site directly. One note, you have to make sure you select a mirror (don't choose the first or second line).

And the answer is....

(drum roll)

(still drum roll)

(more drum roll)

(even more drum roll)

man startup is slow

(ta-da)

finally

but no dice. Doesn't not bring it up.

So far the ideal J2EE development environment for me is RAD 6.0 with the WTE 5.1 (not 6.0). At least the environment I would be comfortable to tell people to use.

Archimedes Trajano said...

I thought I just needed geronimo-jetty.xml

Too bad that didn't work either.

Archimedes Trajano said...

For that matter, why the heck are there samples with geronimo's installation file. They shouldn't put in samples with the exception of a simple IVT servlet and JSP.

Archimedes Trajano said...

Seems that I am trying to get blood from stone. I am using JDK 1.5 since I plan to use Tapestry 4.0 and annotations.

http://www.mail-archive.com/user@geronimo.apache.org/msg02401.html

Wonder what the heck they did to get to to not work in JDK 1.5

Archimedes Trajano said...

I decided to try and use JBoss as my J2EE server. Haven't thought of using it for ages, but might as well. I'd rather have Geronimo working, but no luck with it.

I want to have the use of EJBs, I can't find in Spring how to do MDBs.

Archimedes Trajano said...

Well I got my app to deploy on JBoss. That's all well and good, but it does not allow for replacement of JSP code without having to go through a republish cycle (same with Websphere 6 on RAD) which I think is very annoying.

Archimedes Trajano said...

Man Jonas is a pain too. I guess the best one is still WebSphere Application Developer 5.1 for J2EE development.