How To Create Maven Project In Eclipse? A Step-By-Step Guide
By Rohan Vats
Updated on Jun 17, 2025 | 21 min read | 9.77K+ views
Share:
For working professionals
For fresh graduates
More
By Rohan Vats
Updated on Jun 17, 2025 | 21 min read | 9.77K+ views
Share:
Table of Contents
Do you know? Maven’s central repository, with over 3.5 million packages, is one of the largest ecosystems for Java dependencies globally, and its enterprise-grade adoption is evident as over 2,000 companies rely on Maven for their software development pipelines. |
Building a Maven project in Eclipse greatly improves Java development by automating build processes and simplifying dependency management through integrated tools. Maven’s powerful project management features make configuration and maintenance seamless, ensuring consistency across different environments.
This streamlined approach allows developers to focus more on writing code and less on managing complex setups, leading to more efficient and reliable project workflows.
In this blog, you’ll learn how to efficiently create and manage Maven projects in Eclipse, an IDE for Java developers. You’ll also understand how to use Maven’s powerful features for building Java-based applications.
Eclipse IDE, with its built-in Maven support via the m2e plugin, has become the industry standard for managing Java projects. With over 84% of Java developers using Eclipse, its seamless Maven integration boosts productivity by simplifying dependency management and automating builds.
The Maven Central repository, accessible through Eclipse, hosts over 3.5 million packages, providing a vast ecosystem for Java development. This integration streamlines project setup and contributes to Maven’s critical role in enterprise and open-source Java projects, with nearly 2 billion downloads annually.
In 2025, professionals skilled in tools like Maven for automating builds and managing dependencies will be in high demand. If you're looking to develop expertise in Java development, here are some top-rated courses to help you get there:
Now, let’s get into the step-by-step process of creating a Maven project in Eclipse:
Before creating a Maven project in Eclipse, ensure that Maven is installed and configured in Eclipse. Here’s how to do it:
Now, you're ready to start creating your Maven project in Eclipse!
Also Read: Top 5 Exciting Maven Multi-Module Project Ideas & Topics for Beginners
Creating a new Maven project in Eclipse begins with setting up the project structure and configuring basic settings such as Group ID and Artifact ID.
Here’s how to do it:
Now, you'll specify the Group Id and Artifact Id:
Select maven-archetype-quickstart as the archetype, which is a template for creating a simple Java project. Click Next.
You will now have a project setup similar to the following:
my-app
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── mycompany
│ └── app
│ └── App.java
└── test
└── java
└── com
└── mycompany
└── app
└── AppTest.java
You can get a better hang of Java with upGrad’s free Core Java Basics course. It covers variables, data types, loops, and OOP principles to build strong coding skills. Perfect for aspiring developers, students, and professionals transitioning to Java.
Also Read: How To Create Dynamic Web Project Using Eclipse [Step By Step Explanation]
Now, you'll explore the Maven project structure, including the pom.xml file for configuration, and the src directories for source code and tests.
Software Development Courses to upskill
Explore Software Development Courses for Career Progression
Also Read: Learn 50 Java Projects With Source Code (2025 Edition)
After creating the Maven project in Eclipse, you'll see a basic Java class and a test class. Let's walk through each file:
App.java (Main Application Class): Located in src/main/java/com/mycompany/app/App.java, this class is a simple "Hello World" application.
package com.mycompany.app;
public class App {
public static void main(String[] args) {
System.out.println("Hello, Maven!");
}
}
Explanation: This class defines the main method, which prints "Hello, Maven!" when executed. App.java is the entry point of the application.
Output:
Hello, Maven!
AppTest.java (Unit Test Class): Located in src/test/java/com/mycompany/app/AppTest.java, this test class verifies the functionality of the App class.
package com.mycompany.app;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class AppTest {
@Test
public void testAppHasMessage() {
App app = new App();
assertTrue("The message should contain 'Maven'", app.main() != null && app.main().contains("Maven"));
}
}
Explanation: This test class uses JUnit to test if the message "Maven" is printed when the main method is called. The test class is located under src/test/java and follows the JUnit structure for writing unit tests.
Output:
The message should contain 'Maven'
Also Read: IntelliJ IDEA vs. Eclipse: The Holy War!
Next, you'll build and run your Maven project in Eclipse using Maven commands to install dependencies and compile the code, ensuring everything is set up correctly.
1. Build the Project: To build the Maven project, you can use the Maven Goals in Eclipse.
This command will clean the project, install dependencies, and package it.
2. Run the Project: To run the project:
Hello, Maven!
Also Read: How To Create Spring Boot Project In Eclipse
Maven uses dependencies to add external libraries to your project. You can add dependencies to your pom.xml file under the section. For example, to add JUnit for testing, you can include the following dependency:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
After adding this dependency, Maven will automatically download the JUnit library when you build the project.
Are you a full-stack developer wanting to integrate AI into your workflow? upGrad’s AI-Driven Full-Stack Development bootcamp can help you. You’ll learn how to build AI-powered software using OpenAI, GitHub Copilot, Bolt AI & more.
Also Read: How to Code, Compile, and Run Java Projects in 2025
Next, let’s look at what is POM in Maven.
Learn: Spring Developer Salary in India: For Freshers & Experienced
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>
What happens when this pom.xml is used in a Maven project?
Output Explanation for Maven Build:
When you run the following command in the terminal:
mvn clean install
Here’s what you can expect:
Here is a simple run-through of essential POM elements:
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.
Also Read: Java Language History: Key Milestones and Development
Subscribe to upGrad's Newsletter
Join thousands of learners who receive useful tips
upGrad’s Exclusive Software Development Webinar for you –
SAAS Business – What is So Different?
Next, let’s look at some of the benefits of creating a Maven Project in Eclipse.
Maven’s integration with Eclipse enables developers to automate builds, manage dependencies directly from the IDE, and leverage features like real-time error reporting and one-click project setup.
Eclipse’s m2e plugin further simplifies the process, letting you run Maven goals, manage dependencies, and configure project settings without leaving the IDE.
This combination is a key productivity driver for teams and individuals building scalable, maintainable Java applications.
Here are some key benefits of using Maven Project in Eclipse:
Maven automates dependency management via pom.xml, allowing easy addition, updating, or removal of libraries without manual JAR handling. Eclipse integrates seamlessly, enabling quick access to dependencies from Maven Central while avoiding version conflicts.
Example: With a simple line in your pom.xml like this:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
Eclipse will automatically download and include JUnit in your project, without needing you to manually manage the JAR file.
Maven ensures a consistent build process across environments by standardizing project builds. In Eclipse, it manages the entire lifecycle, from compiling to packaging and deployment, making collaboration and cross-machine work seamless.
Example: By running mvn clean install, Maven will clean, compile, and install the project’s dependencies, ensuring that the build process is consistent each time it is executed.
Maven integrates smoothly with CI tools like Jenkins and Travis CI, automating builds and tests. In Eclipse, you can easily configure your Maven project in Eclipse to work with CI/CD pipelines, ensuring automated testing and deployment.
Example: After configuring Maven in Eclipse, you can integrate with Jenkins to automatically trigger builds and tests each time a developer commits changes to the version control system, streamlining the development process.
Maven enforces a standardized project structure, aligning with industry best practices. In Eclipse, this structure makes it easier for new team members to understand the project layout, streamlining onboarding and collaboration.
Example: A typical Maven project structure in Eclipse might look like this:
my-app
├── pom.xml
└── src
├── main
│ └── java
│ └── com
│ └── mycompany
│ └── app
│ └── App.java
└── test
└── java
└── com
└── mycompany
└── app
└── AppTest.java
This structure separates source code (src/main/java) from test code (src/test/java), making the project easier to navigate and maintain.
Maven simplifies version control by defining all dependencies and plugins in the pom.xml, preventing conflicts across environments. In Eclipse, this integration makes tracking changes, managing versions, and collaborating with teams easier.
Example: By managing dependencies through pom.xml, if a new version of a library is required, you can update the version in a single file, and Maven will automatically handle the rest, ensuring consistency across all environments.
Maven supports testing frameworks like JUnit and TestNG, making it easy to run unit tests, check code coverage, and generate reports in Eclipse. It also automates test execution during the build process, ensuring thorough testing at each stage.
Example: After adding the JUnit dependency in pom.xml, running mvn test in Eclipse will automatically execute your unit tests, and Maven will generate a report on the results, helping you catch errors early in the development cycle.
These features help boost productivity, improve collaboration, and ensure smooth project management, making it a top choice for Java developers.
Also Read: Best Java Courses Online (Recommended by Developers)
Next, let’s look at some of the best practices to keep in mind while creating a Maven project in Eclipse.
Following best practices for a Maven project in Eclipse ensures efficient management, streamlined dependencies, and scalable development. By using a consistent structure, managing dependencies in pom.xml, and automating builds, you maintain clean code, enhance collaboration, and reduce errors in both solo and team environments.
Here are some key strategies to keep in mind:
Stick to the default Maven directory structure, which separates source code (src/main/java) from test code (src/test/java). This helps maintain organization as the project grows.
Example: By following the default structure, when your project scales, you can easily distinguish between production code and test code. For instance, placing the main application logic in src/main/java and test cases in src/test/java makes it clear and easy for collaborators to understand the project layout.
Always specify dependencies with clear and specific versions in the pom.xml file. This prevents version conflicts and ensures that the project remains stable across different environments.
Example: By defining the version explicitly:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
This ensures that everyone working on the project uses the same version of JUnit, preventing issues caused by differing versions of dependencies.
Define profiles in the pom.xml to handle different environments (development, testing, production). This allows you to customize behavior based on the environment without changing the project structure.
Example: You can define separate profiles for development and production, which could use different configurations or dependencies, like:
<profiles>
<profile>
<id>development</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>production</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
This allows you to easily switch between environments and use different settings as required.
Manage all dependencies and plugins through the pom.xml to ensure a clean and reproducible build process. Avoid including dependencies directly in individual files.
Example: Instead of manually managing dependencies, you can rely on Maven to handle everything:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>
</dependencyManagement>
This reduces dependency version conflicts and ensures that the right libraries are always available for your project.
Run mvn clean frequently to ensure that your project builds from a clean slate, removing any previously compiled files or dependencies that might cause issues.
Example: If you're encountering unexpected behavior after making changes to dependencies or code, running mvn clean install ensures that the build is fresh and free from any old artifacts that might affect the process.
These strategies help improve collaboration, simplify dependency management, and keep the project environment consistent and reproducible.
Also Read: Exploring the 14 Key Advantages of Java: Why It Remains a Developer's Top Choice in 2025
Next, let’s look at how upGrad can help you learn Java programming.
To effectively create a Maven project in Eclipse, start by organizing the project structure, clearly defining dependencies in the pom.xml, and properly configuring Maven plugins. This ensures that your project is scalable, maintainable, and easy to manage. Mastering these steps not only helps you create efficient projects but also enhances your employability as a skilled Java developer.
If you’re looking to build these skills and take your development career to the next level, upGrad can help. With their hands-on experience and expert guidance, you can master tools like Maven and Eclipse to build scalable applications.
In addition to the programs covered in the blog, here are some additional courses to complement your learning journey:
If you're unsure where to begin or which area to focus on, upGrad’s expert career counselors can guide you based on your goals. You can also visit a nearby upGrad offline center to explore course options, get hands-on experience, and speak directly with mentors!
Boost your career with our popular Software Engineering courses, offering hands-on training and expert guidance to turn you into a skilled software developer.
Master in-demand Software Development skills like coding, system design, DevOps, and agile methodologies to excel in today’s competitive tech industry.
Stay informed with our widely-read Software Development articles, covering everything from coding techniques to the latest advancements in software engineering.
References:
https://www.browserstack.com/guide/create-maven-project-in-eclipse
https://www.loginradius.com/blog/engineering/how-to-use-maven-dependency-in-eclipse
https://pg-p.ctme.caltech.edu/blog/coding/what-is-maven
https://arxiv.org/html/2504.07310v1
This occurs when Eclipse uses a different JDK version than your command line Maven or has stale project metadata. Check that your Eclipse project's Java Build Path matches the Maven compiler plugin version in your pom.xml (maven.compiler.source and maven.compiler.target). Right-click project > Properties > Java Build Path > Libraries and ensure the correct JRE version is selected. Try refreshing the project (F5) and running Maven > Reload Projects to sync Eclipse's incremental compiler with Maven configuration.
Enable automatic dependency resolution by going to Window > Preferences > Maven and checking "Automatically update Maven projects configuration" and "Download repository index updates on startup." Also enable "Refresh workspace automatically" in General > Workspace preferences for real-time updates. Configure Eclipse to download sources and Javadocs automatically by checking those options in Maven preferences. If dependencies still don't auto-import, enable "Update Maven project on save" in Maven > User Interface preferences to force pom.xml re-reading on save.
This happens when Eclipse's m2e plugin doesn't know how to handle specific Maven plugin executions during incremental builds. Add lifecycle configuration to your pom.xml using pluginManagement section with lifecycle-mapping-metadata.xml or use m2e-specific configuration. Right-click the error in Problems view and select "Quick Fix" to automatically generate necessary lifecycle configuration. Some plugins like exec-maven-plugin require explicit m2e connector installation from Eclipse Marketplace to work properly with Eclipse builds.
Eclipse caches dependency resolution differently than command line Maven, leading to different conflict outcomes. Use Maven Dependencies view (Window > Show View > Maven > Maven Dependencies) to visualize dependencies Eclipse uses and compare with mvn dependency:tree output. Clear Eclipse's dependency cache by deleting .metadata/.plugins/org.eclipse.m2e.core/nexus directory and refresh your project. Force Eclipse to match Maven CLI resolution by enabling "Use Maven output folders" in project properties and ensuring the same settings.xml file usage.
This indicates Eclipse hasn't properly recognized the Maven project structure or source folders are misconfigured in build path. Right-click project and select Maven > Reload Projects to force Eclipse to re-read pom.xml and reconfigure source folders. Check project Properties > Java Build Path > Source to verify Maven source folders are listed correctly. If missing, remove project from Eclipse (without deleting files) and re-import as existing Maven project to reset source folder recognition.
Configure remote debugging by adding MAVEN_OPTS environment variable: -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000. Create Remote Java Application debug configuration in Eclipse pointing to localhost:8000, then run Maven goal from command line with debug options. For m2e plugin debugging, start Eclipse with -Xdebug options and connect second Eclipse instance as remote debugger. Enable Maven debug output in Run Configurations > Maven Build by adding -X or -e flags to Goals field.
Eclipse and Maven use different test runners, classpaths, or JVM configurations leading to inconsistent results. Check that Eclipse's JUnit runner version matches Maven Surefire plugin configuration and same test scope dependencies are used. Verify system properties and JVM arguments from Surefire plugin are set in Eclipse's test run configuration. Compare Eclipse's test classpath (Run Configuration > Classpath) with Maven's using mvn dependency:build-classpath -DincludeScope=test to identify differences.
Import the entire multi-module project as single Maven project rather than individual modules to let Eclipse understand module relationships. Use "Import existing Maven projects" wizard selecting root directory with parent pom.xml - Eclipse automatically detects all modules. For circular dependencies, refactor code to extract common functionality into separate shared module since proper Maven design prohibits cycles. Disable automatic building (Project > Build Automatically) and manually trigger builds in correct order if working with complex temporary interdependencies.
Eclipse's m2e plugin has more conservative SNAPSHOT update policies than command line Maven, checking less frequently for updates. Go to project Properties > Maven and ensure "Resolve Workspace projects" is enabled for multi-module scenarios. Force SNAPSHOT updates by right-clicking project > Maven > Reload Projects or Maven > Update Project with "Force update of snapshots/releases" checked. Configure more frequent SNAPSHOT checks in Window > Preferences > Maven > User Settings by modifying updatePolicy in repository definitions.
Go to Window > Preferences > Maven > Installations, click "Add" and browse to your external Maven home directory. Select the external installation and click "Apply" to make it default for new projects. For existing projects, right-click > Properties > Maven and change Maven runtime to external installation. Update User Settings path to point to your external Maven's settings.xml file and restart Eclipse. This ensures Eclipse uses same Maven version, plugins, and configurations as command line builds.
Eclipse's m2e plugin doesn't automatically recognize all Maven plugin-generated sources, requiring manual configuration or m2e connectors. Check Eclipse Marketplace for m2e connectors specific to your plugin (Help > Eclipse Marketplace). If no connector exists, manually add generated source directories: right-click project > Properties > Java Build Path > Source > Add Folder. Configure build-helper-maven-plugin to add source directories which m2e usually recognizes, or run mvn generate-sources before Eclipse can see generated files.
This warning indicates Eclipse's project configuration doesn't match current pom.xml state due to caching issues or incomplete updates. Try right-click project > Maven > Reload Projects, then Maven > Update Project with "Force update" options checked. Check .metadata/.log file for specific error messages indicating the root cause of configuration mismatches. Delete .metadata/.plugins/org.eclipse.m2e.core directory (with Eclipse closed) and reimport project to resolve persistent issues. Verify pom.xml validity with mvn validate before attempting Eclipse fixes.
408 articles published
Rohan Vats is a Senior Engineering Manager with over a decade of experience in building scalable frontend architectures and leading high-performing engineering teams. Holding a B.Tech in Computer Scie...
Get Free Consultation
By submitting, I accept the T&C and
Privacy Policy
India’s #1 Tech University
Executive PG Certification in AI-Powered Full Stack Development
77%
seats filled
Top Resources