What Is Maven?
Maven is all about large-scale Java-based software projects. It advocates a standard lifecycle, standard directory layout, various best practices, extensive reports, documentation facilities, and it is totally extensible through plug-ins to boot. You may, of course, customize the default directory layout and lifecycle if you have special needs. The maven core is an engine scans your project directory tree for pom.xml files and executes the build lifecycle based on the information in the pom.xml.
Maven advocates using a standard directory layout for your source files, resources, and intermediate artifacts. The benefit of this convention is that developers feel right at home when they browse a new project and don't have to specify a lot of information because Maven assumes the files are organized according to the recommend directory layout. You may override everything of course, but usually it's counter productive. Table 1 contains the standard directory layout for a single project.
Files | Explanation |
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/filters | Resource filter files |
src/main/assembly | Assembly descriptors |
src/main/config | Configuration files |
src/test/java | Test sources |
src/test/resources | Test resources |
src/test/filters | Test resource filter files |
src/site | Site |
LICENSE.txt | Project's license |
README.txt | Project's readme |
target |
Table 1: Directory layout for a single project.
Maven promotes a standard build lifecycle where various plugins may hook into in order to customize or enhance it. The standard lifecycle phases are described in Table 2. The <packaging> element in the pom.xml file determines the build lifecycle for a specific project. When building a project using a command such as "mvn install" Maven will go through all the lifecycle phases up to (and including) the specified phase. The standard lifecycle makes the whole process much simpler because you don't have to graft it into the build system yourself. The good people of Maven put all the lifecycle phases that yo are likely to need even in a complex project (source-code generation, for instance) and if you happen to be an unlikely person then you are free to customize the lifecycle and hook into it using custom plugins.
Files | Explanation |
validate | validate the project is correct and all necessary information is available |
generate-sources | generate any source code for inclusion in compilation. |
process-sources | process the source code, for example to filter any values. |
generate-resources | generate resources for inclusion in the package. |
process-resources | copy and process the resources into the destination directory, ready for packaging. |
compile | compile the source code of the project. |
process-classes | post-process the generated files from compilation, for example to do bytecode enhancement on Java classes. |
generate-test-sources | generate any test source code for inclusion in compilation. |
process-test-sources | process the test source code, for example to filter any values. |
generate-test-resources | create resources for testing. |
process-test-resources | copy and process the resources into the test destination directory. |
test-compile | compile the test source code into the test destination directory. |
test | run tests using a suitable unit testing framework. should not require the code be packaged or deployed. |
package | take the compiled code and package it in its distributable format, such as a JAR. |
integration-test | process and deploy the package if necessary into an environment where integration tests can be run. |
verify | run any checks to verify the package is valid and meets quality criteria. |
install | install the package into the local repository, for use as a dependency in other projects locally. |
deploy | done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.. |
Table 2: Standard lifecycle phases.