2015/01/29

Basic Maven project setup

A basic Maven project consists of a project name, project id, and version.

<project>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>my-application</artifactId>
    <groupId>com.project.my-application</groupId>
    <version>0.0.1-SNAPSHOT</version>
</project>

From here, the structure of the source folders depends on the Maven plugins used to build the code. In most cases this will be Java code and following a generic main/test structure. Simply put all your code into the src folder and run mvn clean install to compile the code and place your JAR into the Maven repository (we’ll take a look at what this means in a later article).

If you look at the groupId above, you’ll notice that it looks like a package name in Java. This can match the package name but it doesn’t have to. In most cases a Java project will have multiple package names but only one groupId. Pick a groupId that uniquely identifies your project name. Similarly, the applicationId should identify your application within your project. The modelVersion tag is required by Maven, and is always set to 4.0.0.

There you have it! This basic Maven project builds a Java Archive that can run under a JVM.

No comments:

Post a Comment