Monday, May 12, 2008

creating a WebObjects application with Maven: WOProject, WOCreator, and WOLips


I'm starting a project working with WebObjects. I'm most familiar with
Tomcat, J2EE standards, and Ant/Maven, so let's see what it takes to get a working application.

WOCreator

A friend found posts referencing a different project WOCreator, and this one turned out to be very easy to install. Just follow the instructions on their main page. Here's what I ended up using (though I believe the 'repository' flag is wrong, but I suspect it's not being used in my case).


mvn com.bbc.newsi.mvn.plugins:maven-wocreator-plugin:create-project \
-DgroupId=com.icentris.webdynamics -DprojectName=sampleCreator \
-Drepository=file:///home/trent/.m2/repository -DwebObjectsVersion=5.4


The one difficulty I had was with all the jars. First of all, you have to get the WebObjects jars into your repository; they provide a script that will install all the required jars into your local repository. This is incredibly helpful. Second, you have to manually install the following jars if you don't already have them; a quick web search will tell you where you can get them:
  • com.sun.jdmk jmxtools 1.2.1
  • com.sun.jmx jmxri 1.2.1
  • javax.jms jms 1.1
Quite frankly, after the struggles with WOProject, this is an awesome tool because it just works: you run the Maven tasks 'create-project', then 'package', then 'jetty:run-war'. The only thing that hung me up for a minute was the URL; Jetty started up and reported that I could go to the following URL:

http://trent-laptop/sampleCreator-application-1.0-SNAPSHOT/WebObjects/sampleCreator-application-1.0-SNAPSHOT.woa

However, this was wrong; I had to add the right port and change the context to the name I gave to 'create-project':

http://trent-laptop:8080/sampleCreator/WebObjects/sampleCreator-application-1.0-SNAPSHOT.woa

Wonderful! I have an application that I was able to tweak with 'webobject' tags and see something work. It only took about 24 hours because I started with WOProject first (see below). But start with WOCreator and you'll be working in no time.


WOProject bootstrap

It looks like the WOProject will install the jars and set up a sample app with Maven.

At first, I can't get the bootstrap to work:

[INFO] The plugin 'org.apache.maven.plugins:maven-wobootstrap-plugin' does not exist or no valid version could be found


I really struggled with this plugin stuff. The thing that finally seemed to get it to at least recognize the 'mdimension' repository was to create a dummy pom.xml and then add the plugin info to the 'reporting' section of a pom:


<plugins>
...
<plugin>
<groupid>org.objectstyle.woproject.maven2</groupid>
<artifactid>maven-wobootstrap-plugin</artifactid>
</plugin>
...
</plugins>


I then had to add the POM file directly to my local repo copy (to get around it's inability to find the org.apache.commons.lib.SystemUtil class):


http://webobjects.mdimension.com/maven2/releases/org/objectstyle/woproject/maven2/maven-wobootstrap-plugin/2.0.14/maven-wobootstrap-plugin-2.0.14.pom


... and I finally got something to work. Here's the final command:

mvn org.objectstyle.woproject.maven2:maven-wobootstrap-plugin:install \
-DwebObjectsLibFolder=/usr/local/apple/Library/WebObjects/lib -DwebObjectsVersion=5.4


That's frustrating, because I'm not quite sure what piece I added that made it all work. I spend about 6 hours fooling around with this stuff. Maybe I'll try and figure out this plugin craziness sometime.

Right now, I want to see if I can get the archetype setup to work.



WOProject archetype

I start with the following default from their example:

mvn archetype:generate -DarchetypeCatalog=local


It promps me to choose:

Choose archetype:
1: local -> woapplication-archetype (WebObjects Application Archetype)
Choose a number: (1):


... but the first time I got this error:

org.apache.maven.archetype.downloader.DownloadNotFoundException: Requested download does not exist.


Fine. So I try this, but it's totally wrong because it dies before I can even choose:

mvn org.objectstyle.woproject.maven2:archetype:generate \
-DarchetypeCatalog=local


And I graduate to a "FATAL ERROR" with this attempt:

mvn org.objectstyle.woproject.maven2:woapplication-archetype:generate \
-DarchetypeCatalog=local


At this point, I choose the first one again, and it seems to work because it prompts me for more and starts making the project. Argh! Is that good now that something's working, or bad because I have no idea what fixed it?

BTW, if you get the following error, make sure there's no pom.xml in the current directory:

[ERROR] org.apache.maven.archetype.exception.InvalidPackaging: Unable to add module to the current project as it is not of packaging type 'pom'


I learned I have to specify the "WebObjectsVersion" because it defaults to something else and doesn't ask you the first time around. (You could also answer "n" at the end of the other questions so that it prompts you for it, but then you have to answer all the questions again.) While I'm at it, I might as well specify it all.

So here's the final command:

mvn archetype:generate -DarchetypeCatalog=local -DWebObjectsVersion=5.4 \
-DgroupId=icentris-webdynamics -DartifactId=sample -Dversion=0.1 -Dpackage=app

Although this creates a basic app, the app doesn't build correctly with 'mvn package'. I tried a few things but it cannot find a properties file (that exists), and it says to run another buildfile (that doesn't exist):

org.objectstyle.woenvironment.env.WOBuildPropertiesNotFoundException: Could not find wobuild.properties. Run the buildfile: woproperties.xml first.

I've given up on this set of tools for now, mostly because I've found something else that works.


WOLips

I have to mention WOLips: it claims to be "the toolset that Apple itself uses internally"; it certainly has great documentation (which I used to help with WOCreator above), and a colleague has successfully started porting his Mac-based development environment to WOLips so that the rest of us can play with it. Unfortunately, I followed their instructions to install with Eclipse Update Manager and I ended up with a project that has a bunch of errors and a directory structure that doesn't match their screen shots (and their proposed fixes don't remedy the situation). Well, that was a dead-end, but at least it was a quick one!

Update: I've got WOLips working, and fairly easily. I don't know what I did, but I erased all my earlier stuff and started with a new WO Application and I got something without any errors, and something that ran great when I right-clicked on Application.java and choose "Run As" a "WOApplication. This generates some build files for an Ant build process as well. If you have to work with a WebObjects application, I've heard that the UI is essential so you really have to use WOLips.

No comments: