Apache Maven Tutorials and Dependencies

Apache Maven is very popular tool among Java developers for building their projects, in this section we are giving many tutorials on Maven and its use in getting the Java library dependencies in the project.

Apache Maven Tutorials and Dependencies

Apache Maven Tutorials, Articles and Dependencies release

Apache Maven is a very popular tool for managing the Java projects and building the distributable packages of your project. Maven is a complete project management tool for Java developers which allows developers to compile, test, build and release the Java projects in much easier way. In this section we are going to learn Apache Maven with the help of many tutorials and examples. We will also provide you sample projects to get started with the Maven build tool.

Java developers use Maven for managing their Java projects, but Maven is not limited just to Java it can be used with projects written in C#, Ruby, Scala and others. In this section we will mostly discuss the use of Maven in Java projects.

Maven handles the two important aspects of software development: software building process and managing the dependencies in the software project. Maven uses an XML file called pom.xml for defining the project being built and this file is sufficient to describe all the steps of the software project building. In the pom.xml file developers can define all the dependencies, modules, components, software build order and the plug-ins to use during project building. So, it covers all the aspects of modern software building process.

Maven is powerful and feature rich tool, which comes with the comes with the pre-defined configuration for build-order, directories, many plugins and well established process for building complex projects. Maven build tool automatically downloads the libraries and the plug-ins for your project from the remote Maven 2 Central Repository or from other public repositories. The downloaded libraries are stored on the local repository on the developer's machine. Next time it checks the local repository and if libraries are present in the local repository it uses from there in the project. If the libraries are not present it downloads from Maven 2 Central Repository or other specified repository. This process simplifies the dependency management task and developers can concentrate on the application development.

Maven is building the application on the plugin-based architecture and it can be extended to build the C/C++ projects as well. Maven allows you to build and use the plug-ins to simplify the build process, so it can be extended to make custom build solution for your project.

There are other alternative project build including Gradle and sbt, that do not use the XML. The other project build tools including Gradle, sbt, Apache Ivy and others also uses the Maven dependency from remote Maven repositories. Maven is a very popular project management tool which uses the remote repository for downloading project dependencies and eases the project development lifecycle.

History of Maven

Maven tool was created by Jason van Zyl during the development of Apache Turbine project in 2002. Initially, it was a subproject of Apache Turbine project in 2002. Later on, this Maven was voted and accepted as the top level project at Apache Foundation. The first version of Maven v1.0 was released in July 2004, followed by v2.0 release in October 2005. The version v3.0 of the Apache Maven project was released in October 2010. Now Apache Maven is a top level project at Apache foundation and it is being used by millions of developers around the world for building their projects.

Maven Hello World Project

Now we will see how you can create a simple Hello World Project in maven. It is very easy to compile, build and test your Java project using the Maven build tool. Apache maven uses an XML file for managing the project and its dependencies. The configuration file used in Maven is pom.xml file and we will explain you the details of this file.

Creating first Hello World Project is very easy with maven and you can use the maven-archetype-quickstart archetype for creating the example project quickly. First all install the Maven on your computer and go to the terminal and run following command:

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4

Above command will ask you some questions and then create a sample project for you.

Here is the sample of pom.xml file created with the maven archetype generator:


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.test</groupId>
  <artifactId>hello-world</artifactId>
  <version>1.0</version>

  <name>hello-world</name>
  <url>https://www.roseindia.net</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Maven also generates App.java which is Hello World application in Java. Here is code of App.java:


package com.test;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}

Maven follows the pre-defined directory structure and here is the screen shot of the Maven Hello World application:

Maven Hello World Example

Maven command to compile and package the application

Compiling and packaging the project is very easy with the maven and during this process maven downloads the dependency required in your project.

To compile the project you can use following command:

mvn compile

Above command will compile your project as shown below:

Maven compile command

To package your project you can use following command:

mvn package

Here is the output of the command:

Maven Package Command

The mvn package command compiles all the files inside your project and then creates jar file which you can use to run your project.

You can download the Maven Hello World project from here:

Download Maven Hello World example project.

In this tutorial we introduced you with the Apache Maven tool and explained you the steps to use it for compiling your first project.

Tutorials

  1. Maven dependency for software.amazon.awssdk - ssm version 2.17.162 is released. Learn to use ssm version 2.17.162 in Maven based Java projects
  2. Maven dependency for software.amazon.awssdk - ssm version 2.17.161 is released. Learn to use ssm version 2.17.161 in Maven based Java projects
  3. Maven dependency for software.amazon.awssdk - ssm version 2.17.160 is released. Learn to use ssm version 2.17.160 in Maven based Java projects
  4. Maven dependency for software.amazon.awssdk - aws-query-protocol version 2.17.164 is released. Learn to use aws-query-protocol version 2.17.164 in Maven based Java projects
  5. Maven dependency for software.amazon.awssdk - aws-query-protocol version 2.17.163 is released. Learn to use aws-query-protocol version 2.17.163 in Maven based Java projects
  6. Maven dependency for software.amazon.awssdk - aws-query-protocol version 2.17.162 is released. Learn to use aws-query-protocol version 2.17.162 in Maven based Java projects
  7. Maven dependency for software.amazon.awssdk - aws-query-protocol version 2.17.161 is released. Learn to use aws-query-protocol version 2.17.161 in Maven based Java projects
  8. Maven dependency for software.amazon.awssdk - aws-query-protocol version 2.17.160 is released. Learn to use aws-query-protocol version 2.17.160 in Maven based Java projects
  9. Maven dependency for software.amazon.awssdk - annotations version 2.17.164 is released. Learn to use annotations version 2.17.164 in Maven based Java projects
  10. Maven dependency for software.amazon.awssdk - annotations version 2.17.163 is released. Learn to use annotations version 2.17.163 in Maven based Java projects
  11. Maven dependency for software.amazon.awssdk - annotations version 2.17.162 is released. Learn to use annotations version 2.17.162 in Maven based Java projects
  12. Maven dependency for software.amazon.awssdk - annotations version 2.17.161 is released. Learn to use annotations version 2.17.161 in Maven based Java projects
  13. Maven dependency for software.amazon.awssdk - annotations version 2.17.160 is released. Learn to use annotations version 2.17.160 in Maven based Java projects
  14. Maven dependency for software.amazon.awssdk - aws-sdk-java version 2.17.164 is released. Learn to use aws-sdk-java version 2.17.164 in Maven based Java projects
  15. Maven dependency for software.amazon.awssdk - aws-sdk-java version 2.17.163 is released. Learn to use aws-sdk-java version 2.17.163 in Maven based Java projects
  16. Maven dependency for software.amazon.awssdk - aws-sdk-java version 2.17.162 is released. Learn to use aws-sdk-java version 2.17.162 in Maven based Java projects
  17. Maven dependency for software.amazon.awssdk - aws-sdk-java version 2.17.161 is released. Learn to use aws-sdk-java version 2.17.161 in Maven based Java projects
  18. Maven dependency for software.amazon.awssdk - aws-sdk-java version 2.17.160 is released. Learn to use aws-sdk-java version 2.17.160 in Maven based Java projects
  19. Maven dependency for software.amazon.awssdk - metrics-spi version 2.17.164 is released. Learn to use metrics-spi version 2.17.164 in Maven based Java projects
  20. Maven dependency for software.amazon.awssdk - metrics-spi version 2.17.163 is released. Learn to use metrics-spi version 2.17.163 in Maven based Java projects
  21. Maven dependency for software.amazon.awssdk - metrics-spi version 2.17.162 is released. Learn to use metrics-spi version 2.17.162 in Maven based Java projects
  22. Maven dependency for software.amazon.awssdk - metrics-spi version 2.17.161 is released. Learn to use metrics-spi version 2.17.161 in Maven based Java projects
  23. Maven dependency for software.amazon.awssdk - metrics-spi version 2.17.160 is released. Learn to use metrics-spi version 2.17.160 in Maven based Java projects
  24. Maven dependency for com.applitools - eyes-connectivity-java3-jboss version 3.214.1-beta is released. Learn to use eyes-connectivity-java3-jboss version 3.214.1-beta in Maven based Java projects
  25. Maven dependency for com.applitools - eyes-connectivity-java3-jboss version 3.214.0-beta is released. Learn to use eyes-connectivity-java3-jboss version 3.214.0-beta in Maven based Java projects
  26. Maven dependency for software.amazon.awssdk - kinesis version 2.17.164 is released. Learn to use kinesis version 2.17.164 in Maven based Java projects
  27. Maven dependency for software.amazon.awssdk - kinesis version 2.17.163 is released. Learn to use kinesis version 2.17.163 in Maven based Java projects
  28. Maven dependency for software.amazon.awssdk - kinesis version 2.17.162 is released. Learn to use kinesis version 2.17.162 in Maven based Java projects
  29. Maven dependency for software.amazon.awssdk - kinesis version 2.17.161 is released. Learn to use kinesis version 2.17.161 in Maven based Java projects
  30. Maven dependency for software.amazon.awssdk - kinesis version 2.17.160 is released. Learn to use kinesis version 2.17.160 in Maven based Java projects
  31. Maven dependency for software.amazon.awssdk - elasticloadbalancingv2 version 2.17.164 is released. Learn to use elasticloadbalancingv2 version 2.17.164 in Maven based Java projects
  32. Maven dependency for software.amazon.awssdk - elasticloadbalancingv2 version 2.17.163 is released. Learn to use elasticloadbalancingv2 version 2.17.163 in Maven based Java projects
  33. Maven dependency for software.amazon.awssdk - elasticloadbalancingv2 version 2.17.162 is released. Learn to use elasticloadbalancingv2 version 2.17.162 in Maven based Java projects
  34. Maven dependency for software.amazon.awssdk - elasticloadbalancingv2 version 2.17.161 is released. Learn to use elasticloadbalancingv2 version 2.17.161 in Maven based Java projects
  35. Maven dependency for software.amazon.awssdk - elasticloadbalancingv2 version 2.17.160 is released. Learn to use elasticloadbalancingv2 version 2.17.160 in Maven based Java projects
  36. Maven dependency for software.amazon.awssdk - elasticloadbalancing version 2.17.164 is released. Learn to use elasticloadbalancing version 2.17.164 in Maven based Java projects
  37. Maven dependency for software.amazon.awssdk - elasticloadbalancing version 2.17.163 is released. Learn to use elasticloadbalancing version 2.17.163 in Maven based Java projects
  38. Maven dependency for software.amazon.awssdk - elasticloadbalancing version 2.17.162 is released. Learn to use elasticloadbalancing version 2.17.162 in Maven based Java projects
  39. Maven dependency for software.amazon.awssdk - elasticloadbalancing version 2.17.161 is released. Learn to use elasticloadbalancing version 2.17.161 in Maven based Java projects
  40. Maven dependency for software.amazon.awssdk - elasticloadbalancing version 2.17.160 is released. Learn to use elasticloadbalancing version 2.17.160 in Maven based Java projects