Eclipse and Maven filtering

Filed under: eclipse, filtering, glassfish, maven — digitaljoel @ 1:23 am

I’m working on a web application and using Maven filtering for various properties within some of my web pages and application descriptors. I have my web server pointed to my maven target directory for the deployed webapp. This allows me to build and have my changes immediately available in the webserver. If my changes are in the xhtml files only then there is no need to re-deploy the application or bounce the web server. I can simply refresh my browser and see the changes. This makes for a nice development cycle when editing xhtml files.

The difficulty arises when you bring in the maven filtering.

Netbeans has much better Maven integration than Eclipse. It was also much easier for me to take my existing web application and simply ‘run’ it on the webserver. Unfortunately, when building in netbeans, it would simply copy the resources over to the target directory. For me, this meant death of the page because of the un-filtered properties in the pages.

I’ve been an Eclipse user since 2.x, and am much more comfortable in it. Since I’m not using any maven plugin for Eclipse ( haven’t found one that is worth the effort yet ) I use the Eclipse Java builder to build my java classes directly to my target/classes directory. Now to get the xhtml, properties, xml, etc. files over to where they belong with the appropriate filtering.

My answer was to configure a new builder. In Project Properties, select Builders, then create a new Program builder, with the executable being your mvn executable.

For the working directory, set it to your project directory using the Browse Workspace button. In the Arguments section, put the goals for your maven build. I chose package because it’ll get all the xml, properties, xhtml files, filter them, and copy them to the target directory, which is where my webserver is pointing for its webapp.

The magic is to specify the working set for the builder. Setting it to the src/main/webapp folder of your maven project ( the screenshot isn’t quite correct since it is on a non-maven project, but you get the idea ) means that the builder will only run when a file within that directory is modified.

Using the working set, I’m able to only run the maven target when working on my xhtml files. When I’m doing pure java work, updating the web only files does me no good and is a waste of time.

Now I’m able to work on my xhtml files, press ctrl-b to build, and refresh the browser I’m using for testing to see the changes. Quick turn-around, and no reason to hit the command line to manually run my maven command.

Maybe next time I’ll talk about starting and stopping my glassfish server automatically so I can see my java changes as well.

For information on filtering resources with maven, you can check out



Filed under: general — digitaljoel @ 11:47 pm

Hello, I’m Joel. No, I’m not THE JoelOnSoftware Joel. Just Joel.

Anyway, as I work I find various problems that don’t seem to be well documented on the internet. For years I’ve been googling subjects on the internet to solve problems I’m currently facing in my development efforts, whether commercial or private. Occasionally I’m able to solve some of these problems by taking information from a collection of sites. I figure it’s about time I start giving back. Many of my blog posts will have very specific information for very specific cases, but I just can’t imagine I’m the only person facing these problems.

Currently, I’m working with

  • Java
  • Spring
  • Hibernate
  • Glassfish
  • Eclipse
  • Maven
  • JSF
  • Facelets
  • Liferay
  • JSR-168
  • JSR-286

So most posts will probably deal with those subjects unless I finally start writing my XNA game for Xbox or start playing with the Google app engine.

None of the information I present will ever reflect the views of my employer, nor will I release proprietary code. I hope to get a REAL first post up before too long.

Blog at