Apache Maven - Example

Example

Maven projects are configured using a Project Object Model, which is stored in a pom.xml-file. Here's a minimal example:

4.0.0 com.mycompany.app my-app 1.0 junit junit 3.8.1 test

This POM only defines a unique identifier for the project (coordinates) and its dependency on the JUnit framework. However, that is already enough for building the project and running the unit tests associated with the project. Maven accomplishes this by embracing the idea of Convention over Configuration, that is, Maven provides default values for the project's configuration. The directory structure of a normal idiomatic Maven project has the following directory entries:

Directory name Purpose
project home Contains the pom.xml and all subdirectories.
src/main/java Contains the deliverable Java sourcecode for the project.
src/main/resources Contains the deliverable resources for the project, such as property files.
src/test/java Contains the testing classes (JUnit or TestNG test cases, for example) for the project.
src/test/resources Contains resources necessary for testing.

Then the command

mvn package

will compile all the Java files, run any tests, and package the deliverable code and resources into target/my-app-1.0.jar (assuming the artifactId is my-app and the version is 1.0.)

Using Maven, the user provides only configuration for the project, while the configurable plug-ins do the actual work of compiling the project, cleaning target directories, running unit tests, generating API documentation and so on. In general, users should not have to write plugins themselves. Contrast this with Ant and make, in which one writes imperative procedures for doing the aforementioned tasks.

Read more about this topic:  Apache Maven

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)