Wednesday, March 28, 2007

Integrating OpenLaszlo in a maven build

With the OpenLaszlo 4.0.0 release and the resent hype about flash-based applications, I wanted to try out producing a flash front using a Java stack. So, I went to OpenLaszlo.org and downloaded the release.

But what the...., OpenLaszlo is distributed as a war package (yes, there is a binary installer, but that is just a tomcat with the war deployed in it). Hmm, ... I use maven for building, so I tried to find the dependencies in the maven repository. No luck there.

I ended up pulling apart the warfile, finding the stuff I needed and producing a pom from that. Here are some of the problems I encountered:
  • OpenLaszlo seems to use some dependencies that most other Java applications does not (at least not the ones I build or use). For instance, it is long time since I worked with saxon, and what is "jing" from "thaiopensource"? :-)
  • Many of the dependencies in WEB-INF/lib inside the warfile had no versioning information, neither in the filename nor in the manifest
  • The saxon parser in WEB-INF/lib was a modified one, where the "META-INF/services" part of the jarfile, that sets it up as the default SAXParser, had been taken out. In the pom I produced, I first took the liberty to use a saxon from the maven repository, but this made spring and tapestry from the technology stack of my application fail (the SAXParser in saxon failed to support validation and schemas)
  • The jdom.jar in WEB-INF/lib was something like a 1.0.1, but the latest release from jdom.org is 1.0. Hmm, strange, but the one in the distribution includes a fix for xml comments, which is needed to make things work
In the end, there were some dependencies, that I needed to put in my local maven repository. Either because I could not locate them in the global repository or because I needed to use the special version from the warfile (like with saxon and jdom). The dependencies listed below ended up in my local repository:
  • jdom.jar
  • saxon-6.5.3-lz-p1.jar
  • swflib.jar
  • jing.jar
  • lps-4.0.0.jar
The rest of the dependencies, I could let my pom resolve from the global maven repository. You can download the pom from here, and you then need to do this:
  • Upload it in a maven repository you control (path: org/openlaszlo/openlaszlo/4.0.0/openlaszlo-4.0.0.pom)
  • Download the OpenLaszlo 4.0.0 distribution
  • Upload the 5 jars from WEB-INF/lib (jdom, saxon, swflib, jing, lps) and name them properly to enable the pom to find them (org/openlaszlo/openlaszlo-jdom/4.0.0/openlaszlo-jdom-4.0.0.jar, org/openlaszlo/openlaszlo-lps/4.0.0/openlaszlo-lps-4.0.0.jar, org/openlaszlo/openlaszlo-saxon/4.0.0/openlaszlo-saxon-4.0.0.jar, org/openlaszlo/openlaszlo-swflib/4.0.0/openlaszlo-swflib-4.0.0.jar, org/openlaszlo/openlaszlo-thaiopensource-jing/4.0.0/openlaszlo-thaiopensource-jing-4.0.0.jar)
  • In the pom of your warfile project that is to use OpenLaszlo, include a dependency on the new pom (see below)
  • Include "other stuff you need" from the warfile (see below)
Dependending on the new OpenLaszlo pom is done like this:

<dependency>
<groupId>org.openlaszlo</groupId>
<artifactId>openlaszlo</artifactId>
<version>4.0.0</version>
<type>pom</type>
</dependency>

Are we there yet?
No, we are not. Because OpenLaszlo includes a lot of stuff in the webapp in "lps/" and in "WEB-INF/lps" that is needed to make anything work. In addition to this, you will need some files from "WEB-INF/classes". I did this by depending on the OpenLaszlo warfile in the pom of my application and then specify exactly which parts to include as a war overlay. Like this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0</version>
<configuration>
<dependentWarIncludes>lps/**,WEB-INF/lps/**,WEB-INF/classes/org/openlaszlo/**</dependentWarIncludes>
</configuration>
</plugin>
Of course, you will need to upload the warfile in your repository too. It should be placed and named like this: "org/openlaszlo/openlaszlo/4.0.0/openlaszlo-4.0.0.war".

But why not use war overlays to simply include all from WEB-INF/lib and then avoid all the above stuff about the new pom and uploading jars in a repository you control. Well, you can. But you will end up with a lot of uncontrolled jar dependencies without version information, inside your distribution unit. Not nice.

And then what?
You should then go on and define the OpenLaszlo servlets (see the web.xml of the warfile distribution) and read the documentation.

BTW: I've uploaded the pom to an existing issue in the OpenLaszlo bugtracking tool. Would be nice if they would distribute to the global maven repository when releasing....

6 comments:

Tim said...

Dude, thanks so much for posting this. You saved me several hours of work. Very nice.

Glauber Gallego said...

man... thanks a lot.

It's unbelievable that openlaszlo did not prepare a maven/pom distribution yet.

Anonymous said...

What distribution from Openlaszlo is needed -

http://download.openlaszlo.org/nightly/4.0/5718

Servlet Only
Source
Windows Installer
Linux
Dev Kit
OS X Installer

Per Olesen said...

You should grab the "servlet only" distribution if you want to follow the tip of this blog post.

The others include source and tomcat too.

Felix said...

Thank you very much!

yagmurunsesi said...

thanks
renovationdoctors.com
turizmseyahat.blogspot.com
www.yagmurunsesi.org
yagmurunsesiorg.blogspot.com
turkuntarihi.blogspot.com
websitesiyapamak.blogspot.com
saglik-k.blogspot.com
ders-hane.blogspot.com