Posts tagged ‘ejb-jar.xml’


In this entry I’m going to present a refreshed approach to application versioning in jee6 environment using EJB 3.1 MBean. My previous entry worked fine but had some limitations:

  • first and the most obvious is that it works only under JBoss 5.1 application server
  • secondly it requires java source code filtering for which maven wasn’t prepared
  • and third – it’s confusing for everyone looking at a project with src/main/template directory which is preprocessed by maven resources filter

Yes I could rewrite it so instead of maven it would use annotation preprocessor based on experiences from this and this post but annotation preprocessor for such a simple task just feels wrong.

So let’s start once again from requirements and I’ll walk you through very simple solution which should shed some new light on ejb xml descriptor.


I want to have version of each component easily accessible for users. Version should be applied automatically during build and impossible to change afterwards. It should be also portable.

Solution description

MBean registration using EJB 3.1 Singleton

Registering MBean using ejb3.1 singleton is as simple as adam bien describes it, so I’m not going to analyse it furhter. The only thing to remeber is that you either use MXBean or use convention where your MBean interface has MBean suffix e.g. ApplicationVersionMBean.

XML descriptor and maven resources filtering

Now something that some of readers might consider as harder part – xml deployment descriptor. Some people hate it some people love it but it will let fulfill all the requirements:

  • it’s portable – it’s part of the spec
  • it has all the gadgets available through annotations
  • it promotes bean to enterprise level transparently
  • by declaring injection point and filtering a version number is injected into the bean where it stays forever 🙂

Direct link for the impatient ones.

Summary/Source code

As you can see xml descriptor has its advantages and solution provided is really funky:

  • it’s compact
  • it’s verbose
  • it doesn’t impose any external deps (no annotations)
  • it goes along with maven philosophy as to what should be filtered and what not
  • it’s compact – oh yeah I mentioned this one already 🙂

So there you have it source code on github as usual.