Saturday, March 14, 2009

Maven project architecture

Maven alows the developer to manage Enterprise projects in a modular way. This keep the project in order when it grows in time.

To create new Maven project, you can click File>New Project and select Maven Project



By selecting Next the following dialog will show up:



Click finish. What is important to note is the packaging of the project. It is set on POM.

Next, in the workspace will show the new project. You can than create new Folder and name it modules and underneath this folder you can create other folders that will include your modules or component projects. Your project should look similar to the following:


Clicking the pom.xml should produce the following code:


To create new Module Project, you should click File > New Project and select Maven Module


If your main project was not authomatically selected as parent Project, you should click Browse and select it from the work space. Click Next.


Click finish. The Project will appear in your work space and looks like this:


Close the project, and remove it from the work space. But make sure you don't delete it. Go on your hard disk, where your wrk space is, and copy the new created project in the folder of your main project. After this, it should look something like this:




All we have to do, is to tell maven where to find the new Module. If you open the main project pom.xml, you will notice that Eclipse added your module as follows:


Change the entry in to tag as follows:


The last but not the least is to add the module as a dependency in the main project, so that other sub project- modules can import it as dependency.


In your command console, navigate to the folder of your main project and execute the following maven command:
mvn -X clean install

If everything goes well, maven will end with the following message: