Maven is the build tool of choice for many people due to the simplicity and flexibility of use. The real strength of Maven is vetted when handling real complex projetcs consisting of tens of modules, each requiring elaborate build requirements.
I had faced an uphill task of Mavenising one of our EAR projects. As is the typical case, our project consisted of a EJB module and a WAR module, package together in a EAR module. It was a bit complex as we had to deploy the same application in JBoss and Glassfish. I will write some of that experience here.
Let us consider an enterprise application having a structure as show below:
I will briefly explain what the modules stand for:
swayam-ear: This is the enterprise application
swayam-ejb: Is the EJB module
swayam-war: Is the web module
swayam-shared: Has the ejb remote interfaces. As the name indicates, its shared by the sawaym-ejb and the swayam-war modules
swayam-ear-builder: Used for building all the modules
I am using Netbeans (6.8) and Glassfish for convinience. But you can pretty much use anything.
I have kept things pretty simple. This is how the Remote interface looks like (its a Stateless Session Bean):
@Remote
public interface MySessionBeanRemote {
String sayHello();
}
The most important thing here is the type tag inside the dependency tag. Without this, it will not work.
Putting it all together
Its often very cumbersome to build these modules one by one manually when one of them changes. This is more so in a development environment. So, I will conclude with one pom for building all the modules at one go. This pom is present in the swayam-ear-builder module.
Note that the path of the modules are relative to the pom.
You can build the EAR project and deploy it on Glassfish or JBoss. Once successfully deployed, you can open http://localhost:8080/swayam-war/EjbInvoker This is how it looks like: