Using Unified Expression Language in Maven-Jetty-Plugin
Door: Jan-Kees van Andel, 27 February 2010I like the maven-jetty-plugin. If I download an Open Source project, I usually first look for this baby, because it allows me to quickly run the code in a tested environment. This saves me from a lot of configuration, which would otherwise cause me to lose interest. This often doesn’t take long…
Also, you can completely configure the server in your POM, centralizing configuration and making it thus easy to store server settings in version control. Also, the mvn-jetty-plugin benefits from your existing Maven project configuration, like dependencyManagement.
Some of my buddies at Apache even use the maven-jetty-plugin on a daily basis for their real work. I never got this far, mostly because I’m more familiar with Tomcat, but also because I didn’t really see it as a mature development tool. However, today I decided to give it a chance.
The first attempt
So, I created a simple webapp in my favorite IDE: IntelliJ IDEA and added a Maven2 POM to enable Maven2 support. All well so far.
This was the initial version of my POM:
All was fine, my test app was running, but I needed to enable Unified EL to test MyFaces BeanValidator.
Adding UEL libraries
So, I added a dependency to the UEL API and Impl in my POM, but there was an issue. Every web container already provides the old Expression Language in the jsp-api.jar. So I’m not allowed to package my own EL libraries.
However, I’m quite stubborn, so I tried anyway:
So, let’s give it a try:
mvn jetty:run-exploded
(MyFaces 2.0 requires exploded deployment in Jetty).
Result? BOOOM!
The fix, replacing libraries
The error is completely appropriate. You’re just not allowed to package your own version of the servlet libraries. That’s the job of the servlet container. Failing to do so will result in the error shown above.
So we need to fix this issue by somehow replacing the Jetty libraries or at least changing the way Jetty loads its jsp-api.jar. This is no trivial task however, since jetty is initialized by Maven and doesn’t have a fixed directory structure on disk.
So we need to have some way in Maven to configure the Jetty libraries.
First, Jetty doesn’t have an endorsed mechanism, so that’s a no-go.
But the fix is actually quite easy, just pass some dependencies into the jetty plugin in the POM.
The final POM looks like this:
As you can see, Maven takes care of the heavy lifting. You only need to specify your dependencies and they will override any dependencies with the same groupId, artifactId and type.
So, now I don’t have any reason not to use mvn-jetty-run to test my code!
Happy coding!
