Thursday, August 28, 2008

Splitting a Project into Modules in Maven

The beauty of Maven and Idea is the ease with which they allow you to manage, build and test your applications. Let us suppose we have a project that we wish to build in modules. For sake of simplicity we assume that the project has two basic modules: a webapp module and a core module.

Make a folder on the system for your project. In the folder make two folders by name "core" and "webapp". Also put a pom.xml which should look like:

parent pom

Notable things are the modules node and that the packaging is pom.

In the "core" folder make a folder "src" and put a pom.xml something like:

core pom

Main things to note about the pom is that packaging is "jar". ID are same as those in the parent pom. In "src" folder make two folders "main" and "test". Put a folder named "java" in each of them.

In the "webapp" folder create same directory structure as "core". The pom.xml here would look like:

webapp pom

Make the directory structure webapp -> src -> main -> webapp -> WEB-INF
in WEB-INF put in a web.xml file

You are good to go now. Now all you need to do is mvn idea:idea or mvn eclipse:eclipse (depending on what you are using) while being in the main folder to create the project with its modules.

No comments: