Maven Startup Package

This is a maven built java starter project. It is not a complex presentation of either Maven or Java, it just gives an idea about a valid startup method.

This post is solely written to avoid spending other bundle of hours for figuring out how to configure a multi module java application. There are a number of small things that, if you don't do them, it will not work.

It has been a lot of times I had to spend time in order to figure out things that will be faster forgotten. This time I rush to put this down for future reference. This is not the first or the last post like that :).

The current requirements I have for my projects considering the build are as follows:

  1. Usually the end of line is an ear file
  2. The ear contains a number of web applications, ejb jars and regular dependency jars
  3. Some jars are used to build the ear, however are deployed in the application server classpath so you don't need them bundled in your application
  4. Dependency jar files must be bundled in a specified folder (ear's APP-INF/lib folder). I prefer to deploy there all the jar files, my web applicatioin WEB-INNF/lib folder does not contains any jars.
  5. And very important: each of the modules is a maven artifact, but they are not published not even in the local repository. That means that the jars, the war files etc must "know" of each other without the use of the local maven repository

This is the zip file containing a set of modules under the same Eclipse project. I don't like the idea of having 100 projects in an Eclipse workspace when there is actually only one application. So I will have only one project.

sample maven application

Main points:

The application has two jar files, one web application. The result should be an ear file, so there is a module that is described as an ear as well.

The modules are interdependent, however I don't want the jar files bundled under the web application but under the ear, in the APP-INF/lib folder. The reason: the same library can be used by two other modules, like when you have two web applications defined under the same ear both of them using the struts library.

To be consistent:

  • No jar files under any module
  • I don't have/use any classes folder. If I have classes specifically for a web application for example (form beans, controllers, etc) I put them in a dependent jar. And the jar goes under the ear file's APP-INF/lib folder

These being told, here are the main points you will see in the project:

  • Main folder: there is a pom file that defines all the underlying modules. It has the scope pom and the only meaning is to orchestrate the build of the underlying modules
  • Subsequently, the underlying modules define this top module as parent. This solves the dependency issue when you don't have the modules automatically installed in the local folder repository
  • We have the ear file that depends on the first tier modules (like the attached web application)
  • All the required dependencies are defined at the ear level with "compile" scope, so that they will be all of them bundled. An additional config of the ear plugin is added in the ear pom file in order to ensure the lib files will be created in the APP-INF/lib ear folder, otherwise they will be created in the ear root folder
  • Specific dependencies are defined at the web application level too, of course, however they have the "provided" scope (libraries are used for compilation but are not bundled under the web module)

This pretty much covers everything and normally this is what a programmer requires about 90% of the time.