Using Maven to Manage Your Projects
June 23, 2005
The first step in creating a project that will be managed by Maven is setting up the directory structure. The ASCII art below is a representation of the standard directory structure for a Maven project whose deliverable artifact will be a WAR file. If your project's deliverable will be a JAR file instead of a WAR file, just leave out the src/main/main directory.
/ +- src/ | +- main/ | | +- java/ | | | +- ... | | +- main | | +- webapp | | | | +- ... | +- test/ | | +- java/ | | | +- ... | | +- resources/ | | +- ... | +- site/ | +- xdoc/ | +- ... +- target/ | +- ... +- project.xml +- project.properties +- README.txt +- LICENSE.txt
The bulk of your source files will go in the src/main/java directory. Inside that directory, you organize the code by package name as usual.
The src/test/java directory is where you will store the source files for your unit tests. Those source files also are organized by package name, with convention dictating that a particular test case be placed in the package of the class it is meant to test.
The src/main/resources directory and src/test/resources directory are copied into the classpath of the the build target. You can use these directories to contain any libraries your application will need. The sample webapp ignores these directories in favor of explicit directories beneath the src/main/webapp/WEB-INF directory.
The project.xml file is the key to this whole arrangment. It is an XML description of your Project Object Model (POM), which is what Maven uses to manage your project. For a complete reference on this file, see the Project Descriptor reference on Maven's site.
The project.properties file is where you define properties to override the default Maven properties and customize the project description for your machine.
The README.TXT file is pretty self-explanatory; it contains any information you want people installing/using your application to have.
The LICENSE.TXT file contains the text of the license under which you are distributing your project, e.g., the Apache license or your EULA.
Please note that the current version of Maven breaks its
own best practices recommendations. If you are using
Maven 1.x with the default settings, any files you would
normally place in the
src/site/xdoc directory should be
placed in the root directory. As an alternative, you may
place such files in the recommended location and define the
maven.docs.src property to point
there in your project.properties
file.

