Eclipse How to Create a New Maven Project in Eclipse Estimated reading: 5 minutes 229 views Creating a new Maven project in Eclipse is essential for testers who want to leverage the power of dependency management and build automation. Eclipse, one of the most popular Integrated Development Environments (IDEs) for Java, supports Maven integration, making it easier to configure, build, and manage complex Java projects with just a few clicks. Whether you’re a beginner or an experienced developer, understanding how to create a new Maven project in Eclipse can streamline your development process and set up the foundation for efficient project management.Setting Up Eclipse for Maven ProjectsBefore creating a new Maven project in Eclipse, ensure that your IDE is configured with the Maven plugin. In most cases, the latest versions of Eclipse come with built-in support for Maven. However, if Maven is missing, you can install the Maven Integration for Eclipse (m2e) plugin through the Eclipse Marketplace. This plugin enables Maven support in Eclipse, allowing you to manage dependencies, build configurations, and other Maven-related features directly within the IDE. Verify Maven Integration: Go to Help > Eclipse Marketplace and search for Maven Integration for Eclipse. If it’s installed, you’ll see an option to update. Otherwise, select Install to add Maven support to Eclipse. Eclipse Maven Plugin Tip: Check Java Version Since Maven requires Java, ensure that your Eclipse workspace is configured with the correct Java Development Kit (JDK) version, ideally matching your project requirements.Start a New Maven Project in EclipseTo create a new Maven project, follow these steps:Open Eclipse and navigate to File New Project… Eclipse Create A New ProjectIn the New Project dialog, select Maven Project under the Maven folder, then click Next . Eclipse Maven ProjectThe Select Project Name and Location page will appear. Here, you can specify if you want to create the project in the default workspace or in a custom location. In this guide we’re going to checkUse default Workspace location. Maven Use Default Project LocationCreate a Simple ProjectCreate a Simple Project, you can check the option to Create a simple project (skip archetype selection) to start with a minimal setup without selecting a specific archetype. Eclipse Maven Create A Simple ProjectDefine Group ID and Artifact IDThe Group ID and Artifact ID are crucial identifiers for Maven projects: Eclipse Maven Group ID and Artifact ID Group ID: This is usually a unique identifier for your organization or project. Ex - com.web.demo.app Artifact ID: Represents the project’s name, which will become the final artifact name - WebDemoApp.Next, set the version. You have the option to assign a custom version if you need specific versioning control, or simply use the default setting for a simple setup. Eclipse Maven Set Version Set Version: Leave the default version as 0.0.1-SNAPSHOT if you’re beginning the initial version, or specify a different version if required. Finish: Click Finish to allow Eclipse to create the project structure based on the selected archetype.Explore the Maven Project StructureOnce created, your new Maven project will appear in the Eclipse Package Explorer with a predefined structure. Familiarize yourself with the main folders: src/main/java: This directory holds the main source code. src/test/java: Used for tests. pom.xml: The Project Object Model (POM) file where all dependencies, plugins, and build configurations for the project are defined.Configuring Dependencies in pom.xmlThe pom.xml file is the heart of any Maven project. It allows you to declare project dependencies, build profiles, and plugins. To add dependencies: Open pom.xml: Go to the pom.xml file in the root directory of your project. Add Dependencies: Insert dependencies for libraries or frameworks your project requires. For example, to add JUnit, add this:pom.xml<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13.2</version> <scope>test</scope> </dependency> </dependencies> Save and Update Project: Save the pom.xml file, and Eclipse will automatically download the necessary JAR files from the Maven repository.Build and Run the Maven ProjectMaven projects can be built directly from Eclipse: Build Project: Right-click on the project in the Package Explorer, then select Run As Maven build . This triggers the build process, compiling the code and packaging it based on the pom.xml configuration. Run Project: If you’re working on a simple Java project, you can run the main class by navigating to Run As Java Application .ConclusionBy following this guide, you’ve gained a foundation for effectively using Maven with Eclipse, making it easier to manage complex Java projects with consistency and efficiency. Whether you’re setting up for the first time or integrating Maven into an existing project, mastering these steps will significantly enhance your Eclipse IDE experience.In the next guide, you’ll explore Installing and Configuring Plugins in Eclipse, which will further extend your development capabilities and customization options within the IDE.Tagged:Eclipse Eclipse - Previous How to Install Eclipse IDE Next - Eclipse Installing and Configuring Plugins