Creating a Minimal Enterprise Application with Maven

Setting up a Java EE application is no trivial task. Dependency management, building, and deployment can get pretty complex and require a thorough understanding of deployment descriptors, jars, ears and other artifacts.

In this article, I’m going to present a truly minimal Maven-based setup for the JBoss Application Server (tested with jboss-4.0.5.GA), providing a solid base for further work. The project is an EJB3 demo application which uses JPA to access a database and makes the data available via a remote session bean interface. The application will be deployed in an ear file which contains the required dependencies (unless they are already provided by JBoss).

First of all, download the application and extract it. In the root directory, there’s a pom.xml file (the POM) which defines the top-level project. Each of the subdirectories (ear, ejb, and client) is a Maven project itself with a pom.xml on its own. Apart from some basic values, the top-level POM specifies its sub-modules and gives a list of dependencies for the project. The dependency list is just a declaration, its purpose is to let the other POMs reference dependencies without having to specify the version number.

The ejb module is the heart of the application. It contains the server side source code, which is the data source layer (DAOs), JPA Entities, and a remote facade (in this case: a stateless session bean). The ejb module creates two jar files: One containing all the code, and the other one with all the interfaces and data transfer objects relevant for remote clients (the client-jar).

The ear module contains no source code, its purpose is to configure the deployment descriptor (application.xml) and to package the ejb module’s jar file and all the dependencies into a single ear file, ready for deployment into the jboss application server. You’ll find the created file in ear/target.

The client module implements a simple client application which accesses the server via its remote facade. It can be run from the command line or from within eclipse.

To build the project, run mvn install from the command line. If you want to import the project into eclipse, execute mvn eclipse:eclipse to generate the required .project and .classpath files. From within the IDE, choose File/Import, General/Existing Projects into Workspace, browse to the project’s base directory and hit Finish.

Update 2009-04-13: I updated the demo application to version 0.2. The new version removes an unused import script that caused confusion and the documentation notes where the JBoss dependencies are coming from.

Update 2011-05-22: A lot of time has passed since I posted this article but it’s still popular, so an update is in order. Version 0.3 uses JBoss 4.2.3 and gets its dependencies from the official JBoss Maven repository.

This entry was posted in java and tagged , , . Bookmark the permalink.

2 Responses to Creating a Minimal Enterprise Application with Maven

  1. Matthias Müller says:

    Great job, but with three little mistakes:

    1. In, jboss-annotations-ejb3.jar is missing

    2. You’ve installed the JBoss-Jars with groupId ‘jboss’, but in the POMs you use ‘org.jboss’ .. so one of this has to be changed

    3. Also,the version-tag in the main POM doesn’t cover with the version you’ve installed the artifact with (‘4.0.5.GA’, not ‘4.0.5-GA’)

  2. mafr says:

    Thanks, I’m glad you like it!

    Regarding the issues you discovered: “mvn install” should work without running “” first because all JBoss dependencies are downloaded from the AndroMDA repository (that’s why the version numbers use the unusual ‘4.0.5-GA’ notation).

    I’ll remove the import script in the next release. Please drop me a line if it doesn’t work without the script.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s