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.awscdk - events-targets version 1.112.0 is released. Learn to use events-targets version 1.112.0 in Maven based Java projects
  2. Maven dependency for software.amazon.awssdk - utils version 2.16.99 is released. Learn to use utils version 2.16.99 in Maven based Java projects
  3. Maven dependency for com.amazonaws - aws-java-sdk-bundle version 1.12.21 is released. Learn to use aws-java-sdk-bundle version 1.12.21 in Maven based Java projects
  4. Maven dependency for software.amazon.awscdk - cloudwatch version 1.112.0 is released. Learn to use cloudwatch version 1.112.0 in Maven based Java projects
  5. Maven dependency for com.liferay - com.liferay.asset.categories.admin.web version 5.0.0 is released. Learn to use com.liferay.asset.categories.admin.web version 5.0.0 in Maven based Java projects
  6. Maven dependency for org.liquibase - liquibase-core version 4.4.1 is released. Learn to use liquibase-core version 4.4.1 in Maven based Java projects
  7. Maven dependency for software.amazon.awssdk - sdk-core version 2.16.99 is released. Learn to use sdk-core version 2.16.99 in Maven based Java projects
  8. Maven dependency for com.liferay - com.liferay.asset.categories.navigation.web version 5.0.25 is released. Learn to use com.liferay.asset.categories.navigation.web version 5.0.25 in Maven based Java projects
  9. Maven dependency for software.amazon.awscdk - lambda-event-sources version 1.112.0 is released. Learn to use lambda-event-sources version 1.112.0 in Maven based Java projects
  10. Maven dependency for software.amazon.awscdk - stepfunctions-tasks version 1.112.0 is released. Learn to use stepfunctions-tasks version 1.112.0 in Maven based Java projects
  11. Maven dependency for software.amazon.awscdk - s3-deployment version 1.112.0 is released. Learn to use s3-deployment version 1.112.0 in Maven based Java projects
  12. Maven dependency for software.amazon.awscdk - codepipeline version 1.112.0 is released. Learn to use codepipeline version 1.112.0 in Maven based Java projects
  13. Maven dependency for software.amazon.awssdk - apache-client version 2.16.99 is released. Learn to use apache-client version 2.16.99 in Maven based Java projects
  14. Maven dependency for software.amazon.awssdk - sts version 2.16.99 is released. Learn to use sts version 2.16.99 in Maven based Java projects
  15. Maven dependency for software.amazon.awscdk - ec2 version 1.112.0 is released. Learn to use ec2 version 1.112.0 in Maven based Java projects
  16. Maven dependency for software.amazon.awscdk - kinesisfirehose version 1.112.0 is released. Learn to use kinesisfirehose version 1.112.0 in Maven based Java projects
  17. Maven dependency for software.amazon.awscdk - certificatemanager version 1.112.0 is released. Learn to use certificatemanager version 1.112.0 in Maven based Java projects
  18. Maven dependency for software.amazon.awssdk - dynamodb version 2.16.99 is released. Learn to use dynamodb version 2.16.99 in Maven based Java projects
  19. Maven dependency for software.amazon.awscdk - s3 version 1.112.0 is released. Learn to use s3 version 1.112.0 in Maven based Java projects
  20. Maven dependency for software.amazon.awssdk - netty-nio-client version 2.16.99 is released. Learn to use netty-nio-client version 2.16.99 in Maven based Java projects
  21. Maven dependency for com.liferay - com.liferay.asset.categories.admin.web version 3.0.58 is released. Learn to use com.liferay.asset.categories.admin.web version 3.0.58 in Maven based Java projects
  22. Maven dependency for software.amazon.awscdk - applicationautoscaling version 1.112.0 is released. Learn to use applicationautoscaling version 1.112.0 in Maven based Java projects
  23. Maven dependency for com.graphql-java - graphql-java version 0.0.0-2021-07-17T04-32-45-a31c8171 is released. Learn to use graphql-java version 0.0.0-2021-07-17T04-32-45-a31c8171 in Maven based Java projects
  24. Maven dependency for software.amazon.awssdk - aws-json-protocol version 2.16.99 is released. Learn to use aws-json-protocol version 2.16.99 in Maven based Java projects
  25. Maven dependency for com.liferay - com.liferay.asset.categories.service version 4.0.13 is released. Learn to use com.liferay.asset.categories.service version 4.0.13 in Maven based Java projects
  26. Maven dependency for software.amazon.awssdk - s3 version 2.16.99 is released. Learn to use s3 version 2.16.99 in Maven based Java projects
  27. Maven dependency for com.graphql-java - graphql-java version 0.0.0-2021-07-17T09-36-00-6d744146 is released. Learn to use graphql-java version 0.0.0-2021-07-17T09-36-00-6d744146 in Maven based Java projects
  28. Maven dependency for com.amazonaws - aws-java-sdk-cloudfront version 1.11.729 is released. Learn to use aws-java-sdk-cloudfront version 1.11.729 in Maven based Java projects
  29. Maven dependency for software.amazon.awscdk - cdk-customresources version 1.112.0 is released. Learn to use cdk-customresources version 1.112.0 in Maven based Java projects
  30. Maven dependency for software.amazon.awscdk - codestarnotifications version 1.112.0 is released. Learn to use codestarnotifications version 1.112.0 in Maven based Java projects
  31. Maven dependency for software.amazon.awscdk - s3-notifications version 1.112.0 is released. Learn to use s3-notifications version 1.112.0 in Maven based Java projects
  32. Maven dependency for software.amazon.awssdk - protocol-core version 2.16.99 is released. Learn to use protocol-core version 2.16.99 in Maven based Java projects
  33. Maven dependency for software.amazon.awssdk - sqs version 2.16.99 is released. Learn to use sqs version 2.16.99 in Maven based Java projects
  34. Maven dependency for org.liquibase - liquibase-core version 4.4.1 is released. Learn to use liquibase-core version 4.4.1 in Maven based Java projects
  35. Maven dependency for software.amazon.awssdk - aws-core version 2.16.99 is released. Learn to use aws-core version 2.16.99 in Maven based Java projects
  36. Apache Maven Tutorials and Dependencies
  37. Apache Maven Release History
  38. Maven dependency for ai.h2o - h2o-algos version 3.32.0.4 is released. Learn to use ai.h2oversion 3.32.0.4 in Maven based Java projects
  39. Maven dependency for ai.h2o - h2o-algos version 3.32.0.5 is released. Learn to use h2o-algos version 3.32.0.5 in Maven based Java projects
  40. Maven dependency for ai.h2o - h2o-algos version 3.32.1.1 is released. Learn to use h2o-algos version 3.32.1.1 in Maven based Java projects