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 (
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.
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).
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
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
.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.