Installation#

To install Maven with DNF:

$ dnf install maven

To install Maven manually:

$ wget http://mirror.metrocast.net/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
$ tar xzvf apache-maven-3.6.1-bin.tar.gz
$ cd apache-maven-3.6.1/bin

See https://maven.apache.org/download.cgi.

Creating a Maven Project#

To create a Maven project:

$ mvn archetype:generate \
`` -DarchetypeArtifactId=maven-archetype-quickstart ``
`` -DinteractiveMode=false ``
`` -DgroupId=``com.example`` ``
`` -DartifactId=``app

It will create an app subfolder containing the following files:

  • pom.xml

  • src

    • main/java/com/example/app/App.java

    • test/java/com/example/app/AppTest.java

Compiler#

<project>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>(whatever version is current)</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Native Library#

<project>
  ...
  <packaging>so</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>native-maven-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
           ...
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

See also Native Maven Plugin: Usage.

Eclipse#

To setup Eclipse project:

$ mvn eclipse:clean
$ mvn eclipse:eclipse
$ mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

See also:

Dependencies#

To install a JAR file into the local Maven repo:

$ mvn install:install-file \
   -Dfile=<path-to-file> \
   -DgroupId=<group-id> \
   -DartifactId=<artifact-id> \
   -Dversion=<version> \
   -Dpackaging=<packaging> \
   -DgeneratePom=true

For example:

$ mvn install:install-file \
   -Dfile=/usr/lib/java/jss4.jar \
   -DgroupId=org.mozilla \
   -DartifactId=jss \
   -Dversion=4.8.0-SNAPSHOT \
   -Dpackaging=jar \
   -DgeneratePom=true

To download dependencies:

$ mvn dependency:resolve

To display dependency tree:

$ mvn dependency:tree

To construct classpath:

$ mvn dependency:build-classpath

Building a Maven Project#

To build the classes:

$ mvn compile

The classes will be stored in target/classes folder.

To build the package:

$ mvn package

The package will be stored in target/–SNAPSHOT.jar.

To build the package without running tests:

$ mvn package -Dmaven.test.skip=true

To clean a Maven project:

$ mvn clean

Tomcat Plugin#

To install tomcat8-maven-plugin:

<dependency>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat8-maven-plugin</artifactId>
    <version>3.0-r1756463</version>
</dependency>

See also tomcat7-maven-plugin.

References#