Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconHow To Create Maven Project In Eclipse [Step-By-Step Guide]

How To Create Maven Project In Eclipse [Step-By-Step Guide]

Last updated:
15th Jun, 2023
Views
Read Time
9 Mins
share image icon
In this article
Chevron in toc
View All
How To Create Maven Project In Eclipse [Step-By-Step Guide]

In this article, we’ll tackle some general questions about Maven, such as, “What is Maven?” and discover how you can work on Maven project ideas. You’ll find out how to start Maven projects and the basics you should be familiar with. 

Check out our free courses to get an edge over the competition

What is Maven?

Apache Maven is a project management tool for Java-based projects. It started as a tool to handle tasks in the Jakarta Turbine project. Maven’s developers wanted a standard method to create and manage the project as there were various projects under the Jakarta Turbine one. As a result, they created Maven, which has become one of Apache’s most popular tools. 

Maven projects have easier to build processes and have uniform systems for the same. Accessing project information is very easy with Maven because of its proper and straightforward storage method. 

Ads of upGrad blog

Maven creates projects through POM (project object model), which ensures uniformity among all Maven projects. If you have worked on one Maven project in the past, you won’t face any difficulty working on another. This is one of the biggest reasons why Maven got so popular among developers. 

Check out upGrad’s Advanced Certification in Cloud Computing

How to Create Maven Projects?

Before you create your project in Maven, you’ll need a place where it can be stored. So, we’ll make a directory and start a shell there. To do all this, you have to open your command line and run the Maven goal below:

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

Remember that the code might take some time to execute if you run it right after installing Maven. It happens because Maven downloads the latest plugin jars and other relevant artifacts into your selected repository. Sometimes, you might have to run the command several times for it to succeed. That happens because their remote servers time out sometimes, but it’s not a serious problem, and you can fix it. 

Check out upGrad’s Advanced Certification in Blockchain

After you run the command we mentioned above, you’ll see the following directory with the same as its artifactId. The directory would be:

cd my-app

You’d see that the directory has the following project structure:

my-app

|-- pom.xml

`-- src

    |-- main

    | `-- java

    | `-- com

    | `-- mycompany

    | `-- app

    | `-- App.java

    `-- test

        `-- java

            `-- com

                `-- mycompany

                    `-- app

                        `-- AppTest.java

Here, the src/main/java directory has the source code, the pom.xml is the Project Object Model, and the src/test/java has the test source.  Our code executes the goal archetype:generate. Our code also passes in multiple parameters to this goal. The ‘archetype’ prefix is the name of the plugin, which gives the goal. So our archetype:generate goal creates a small and simple project based on maven-archetype-quickstart. We can say that plugins are only multiple goals grouped for a particular task. 

Explore Our Software Development Free Courses

Learn: Spring Developer Salary in India: For Freshers & Experienced

What is POM?

It is the center of Maven projects and their configuration. The pom.xml file is a configuration file that stores most of the necessary information for building a project in your desired manner. The POM file can be quite massive and complex, but it isn’t necessary to know about its technical aspects to use it properly. The POM for our project is the following:

<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.mycompany.app</groupId>

 <artifactId>my-app</artifactId>

 <version>1.0-SNAPSHOT</version>

 <properties>

   <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.12</version>

     <scope>test</scope>

   </dependency>

 </dependencies>

</project>

Here is a simple run-through of essential POM elements:

  • project: The highest element in every pom.xml file
  • groupId: The identifier of the project’s creator group. It is always unique and is one of the most critical identifiers of a project. 
  • url: It shows the location (the site) of the project. 
  • modelVersion: It shows the version of the object model the current POM is employing. While the object model’s version doesn’t change often, it’s crucial for keeping the project stable.
  • build: It performs tasks related to the management of plugins, declaring the directory structure, etc. 
  • version: It shows the artifact’s version your project has generated. Version management is quite tricky, and Apache Maven helps you substantially with that. 

There are many POM elements, and if you want to work on many Maven project ideas, it would be best to get familiar with them. However, you don’t need to be familiar with all of them if you’re a beginner.

In-Demand Software Development Skills

Building Maven Projects

After the stuff we did in the earlier section, you’d have to use the following command line:

mvn package

It will print multiple actions with the following ending:

[INFO] ------------------------------------------------------------------------

[INFO] BUILD SUCCESS

[INFO] ------------------------------------------------------------------------

[INFO] Total time: 2.953 s

[INFO] Finished at: 2019-11-24T13:05:10+01:00

[INFO] ------------------------------------------------------------------------

You might wonder why this command didn’t have a prefix (like archetype:generate). That’s because it is a phase and not a goal. A build lifecycle is a proper sequence of various phases. Maven executes phases in the arrangement you provide. 

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

Benefits of Using Maven in a Project and How it Simplifies the Build Process

Before learning how to create Maven Project in Eclipse, you should understand why you might want to use Maven in your project. Because it provides a standardised approach to managing dependencies and build processes, Maven is a popular tool in the Java community. Maven enables you to add dependencies to your project without managing them manually. Maven also provides a uniform manner of building your project, making it simple to replicate builds across machines.

Step-by-step Instructions on How to Create Maven Project in Eclipse:

After learning about the benefits of using Maven, let’s get started by creating a Maven project in Eclipse:

  • In Eclipse, go to File > New > Other.
  • Expand the Maven folder, then in the New Project dialogue box, click the “Maven Project” button.
  • Then, click the “Next” button.
  • Select “Create a simple project” before clicking the “Next” button.
  • Enter your project’s Group Id, Artefact Id, and Version.
  • To complete your project, click the “Finish” button.

How to Configure Maven Project Parameters

After you’ve built your Maven project, you can customise it by changing the Group Id, Artefact Id, and Version. Here’s how it’s done:

  • Select “Properties” from the context menu when right-click on your project.
  • Select the “Maven” tab.
  • You can change your project’s Group Id, Artefact Id, and Version here.
  • Click “Apply” and “OK” to save your changes.
  • Installing the Maven plugin and configuring the Eclipse IDE for Maven

You must install the Maven plugin to utilise Maven in Eclipse. Here’s how it’s done:

  • Navigate to Eclipse Marketplace > Help.
  • Look for the term “m2e” (Maven Integration for Eclipse).
  • Select the Maven Integration for Eclipse plugin and press the “Install” button.
  • To install the plugin, simply follow the on-screen instructions.
  • Restart Eclipse after installing the plugin.

How to Add Dependencies to a Maven Project

After configuring your Maven project in Eclipse, you can add dependencies. Here’s how it’s done:

  • Navigate to your pom.xml file.
  • Fill in the dependencies area with the dependencies you require.
  • Save the document.
  • Maven will automatically download and add the dependencies to your project’s classpath.

How to Search the Maven Repository for Dependencies

If you are unsure about the dependencies to employ, you can look them up in the Maven repository. Here’s how it’s done:

  • Please visit MVN Repository website
  • Look for the dependencies you require.
  • Make a copy of the dependency data.
  • Copy the dependency information and paste it into your pom.xml file.

Using Maven with Java 9 (or later versions)

If you want to use Java 9 or later versions, you would have to use version 3.6.0 of maven-compiler-plugin and set maven.compiler.release to the Jave release you wish to target. That’s because the default version of Maven uses older versions of maven-compiler-plugin, which are incompatible with Java 9 and its later versions. Here’s an example of using Maven with later versions of Java:

  <properties>

 <maven.compiler.release>11</maven.compiler.release>

 </properties>

<build>

<pluginManagement>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.8.1</version>

</plugin>

</plugins>
</pluginManagement>

</build>

As all Maven project ideas are based on Java, it would be best to know how to use this tool with later versions. 

Explore our Popular Software Engineering Courses

Also Read: Microservices Using Spring Boot and Spring Cloud

Learn More About Maven

Maven is a fantastic tool for any software professional or project manager. Not only does it help you in keeping things manageable, but it also keeps them simple and easy to comprehend. You can learn a lot about Apache Maven by working on a few Maven project ideas.

Ads of upGrad blog

We hope that you found this article useful. If you have any thoughts or questions, you can let us know through the comments. We’d love to hear from you. 

If you’re interested to learn more about full-stack software development, check out upGrad & IIIT-B’s PG Diploma in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

What do you think of Maven? Let us know. 

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1What is Eclipse?

In the domain of software development and computing, Eclipse is an Integrated Development Environment (IDE). Eclipse IDE is used to build applications using different programming languages such as Java, Python, C, C++, C#, Ruby, PERL, COBOL, Fortran, JavaScript, R, etc. This IDE comes with various plugins and can also be extended for further customization with the help of additional plugins. Eclipse IDE is one of the most popular platforms used by developers across the world and supports the development of rich client applications and even other IDEs. This platform has been created mainly using Java programming language and was originally developed by IBM.

2 Is Maven a DevOps application?

Maven is an open-source tool that supports build automation. It is extensively used in DevOps projects to facilitate automation during the project life cycle management build phase. Maven can be used in conjunction with software applications developed using programming languages such as C#, Java, etc. However, it is used mainly in projects that employ Java as the main programming language. Maven has been developed using a plugin-rich architecture that makes it compatible with any tool that can be controlled using standard input methods. There are pre-defined commands in Maven that can be used to accomplish properly defined tasks like code compilation and packaging.

3Why is Maven needed?

Maven is used by developers to work on a maintainable and reusable, comprehensive but simplistic model for development projects. This application also provides developers with a set of plugins and tools that can seamlessly interact with a declarative model of projects. Maven comes loaded with various useful features and functionalities, making it highly popular and valuable in today's context. Features like a vast, ever-evolving repository of user libraries, streamlined management of dependencies featuring automated updating, robust integrity and error reporting, and easy extensibility for projects using plugins have made developers' lives easier. These are some of the reasons why Maven is the most preferred build automation tool today.

Explore Free Courses

Suggested Blogs

Top 7 Node js Project Ideas &#038; Topics
31566
Node.JS is a part of the famous MEAN stack used for web development purposes. An open-sourced server environment, Node is written on JavaScript and he
Read More

by Rohan Vats

05 Mar 2024

How to Rename Column Name in SQL
46915
Introduction We are surrounded by Data. We used to store information on paper in enormous file organizers. But eventually, we have come to store it o
Read More

by Rohan Vats

04 Mar 2024

Android Developer Salary in India in 2024 [For Freshers &#038; Experienced]
901316
Wondering what is the range of Android Developer Salary in India? Software engineering is one of the most sought after courses in India. It is a reno
Read More

by Rohan Vats

04 Mar 2024

7 Top Django Projects on Github [For Beginners &amp; Experienced]
52053
One of the best ways to learn a skill is to use it, and what better way to do this than to work on projects? So in this article, we’re sharing t
Read More

by Rohan Vats

04 Mar 2024

Salesforce Developer Salary in India in 2024 [For Freshers &#038; Experienced]
909159
Wondering what is the range of salesforce salary in India? Businesses thrive because of customers. It does not matter whether the operations are B2B
Read More

by Rohan Vats

04 Mar 2024

15 Must-Know Spring MVC Interview Questions
34736
Spring has become one of the most used Java frameworks for the development of web-applications. All the new Java applications are by default using Spr
Read More

by Arjun Mathur

04 Mar 2024

Front End Developer Salary in India in 2023 [For Freshers &#038; Experienced]
902374
Wondering what is the range of front end developer salary in India? Do you know what front end developers do and the salary they earn? Do you know wh
Read More

by Rohan Vats

04 Mar 2024

Method Overloading in Java [With Examples]
26187
Java is a versatile language that follows the concepts of Object-Oriented Programming. Many features of object-oriented programming make the code modu
Read More

by Rohan Vats

27 Feb 2024

50 Most Asked Javascript Interview Questions &#038; Answers [2024]
4363
Javascript Interview Question and Answers In this article, we have compiled the most frequently asked JavaScript Interview Questions. These questions
Read More

by Kechit Goyal

26 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon