Creating a Maven project in Eclipse is a fundamental skill for any Java developer aiming to manage dependencies, build lifecycles, and project structure efficiently. Apache Maven standardizes the build process, while the Eclipse IDE provides a visual interface to interact with that standardization. Whether you are building a simple console application, a complex web module, or a multi-module enterprise system, understanding the creation workflow inside Eclipse eliminates configuration headaches and accelerates development velocity The details matter here..
Prerequisites Before You Begin
Before launching the wizard, ensure your environment is correctly configured. This preparation step prevents the most common errors beginners face, such as missing archetypes or incorrect Java versions.
- Eclipse IDE for Java Developers: Download the latest version from the official Eclipse website. The "Eclipse IDE for Java EE Developers" or "Eclipse IDE for Java Developers" packages include the m2e (Maven Integration for Eclipse) plugin by default. If you are using an older distribution or a custom package, verify the plugin is installed via Help > Eclipse Marketplace and search for "m2e".
- Java Development Kit (JDK): Maven requires a JDK, not just a JRE. Ensure
JAVA_HOMEis set in your system environment variables pointing to the JDK installation directory (e.g.,C:\Program Files\Java\jdk-17or/usr/lib/jvm/java-17-openjdk). - Maven Installation (Optional but Recommended): While Eclipse bundles an embedded Maven runtime, using an external Maven installation gives you control over the version and
settings.xmlconfiguration. Configure this later via Window > Preferences > Maven > Installations.
Step-by-Step Guide: Creating a Standard Maven Project
The most common way to start is using the Maven Archetype wizard. Now, archetypes are project templates that generate a standard directory layout and a starter pom. xml file.
1. Launch the New Project Wizard
Open Eclipse. manage to the top menu bar and select File > New > Other.... In the filter box, type "Maven". Select Maven Project under the Maven folder and click Next.
2. Configure Project Location and Workspace
On the first screen of the wizard:
- Create a simple project (skip archetype selection): Leave this unchecked if you want a standard structure (like
src/main/java). Check it only if you want an emptypom.xmlto build from scratch manually. - Use default Workspace location: Keep this checked unless you have a specific directory strategy.
- Add project(s) to working set: Optional, useful for organizing large workspaces. Click Next.
3. Select an Archetype
This is the most critical decision point. The list filters available templates Nothing fancy..
- For a standard Java SE application: Type
maven-archetype-quickstartin the filter box. Select it. This generates a project with aApp.javaclass and a JUnit test skeleton. - For a Web Application (WAR): Select
maven-archetype-webapp. This creates thewebappfolder structure andweb.xml. - For Spring Boot or specific frameworks: It is often better to use Spring Initializr (via File > New > Spring Starter Project) rather than a generic Maven archetype, as it configures dependencies automatically.
Select your desired archetype (e.g., org.apache.maven.archetypes:maven-archetype-quickstart) and click Next Simple, but easy to overlook..
4. Define GAV Coordinates (Group ID, Artifact ID, Version)
You must provide the Maven Coordinates that uniquely identify your artifact in a repository.
- Group Id: Typically your reversed domain name (e.g.,
com.company.projectororg.example). This defines the package structure root. - Artifact Id: The name of the jar/war file without version (e.g.,
my-calculator-app). Use lowercase letters and hyphens. This becomes the project folder name in Eclipse. - Version: Defaults to
0.0.1-SNAPSHOT.SNAPSHOTindicates a project under active development. - Package: Auto-fills based on Group Id. This is the base Java package for your source code (e.g.,
com.company.project).
Click Finish. Eclipse will download the archetype (if not cached), generate the project structure, and resolve initial dependencies defined in the pom.xml.
Understanding the Generated Project Structure
Once the project appears in the Project Explorer, you will see a standardized layout mandated by Maven conventions. Familiarity with this structure is non-negotiable for effective navigation The details matter here..
my-calculator-app
├── src
│ ├── main
│ │ ├── java <-- Production Java source code goes here
│ │ │ └── com
│ │ │ └── company
│ │ │ └── project
│ │ │ └── App.java
│ │ └── resources <-- Configuration files (properties, XML, YAML)
│ └── test
│ ├── java <-- Test source code (JUnit, TestNG)
│ │ └── com
│ │ └── company
│ │ └── project
│ │ └── AppTest.java
│ └── resources <-- Test-specific resources
├── target <-- Compiled output (generated after build)
│ ├── classes
│ ├── test-classes
│ └── my-calculator-app-0.0.1-SNAPSHOT.jar
└── pom.xml <-- Project Object Model (Heart of the project)
Key Directories Explained:
src/main/java: Your business logic lives here. The package structure mirrors the Group Id + Package definition.src/main/resources: Non-code assets likelog4j2.xml,application.properties, or SQL migration scripts.src/test: Mirror structure for unit/integration tests. Maven runs these automatically during thetestphase.target: Never commit this to version control. It is generated output. RunMaven Cleanto delete it.pom.xml: The single source of truth for dependencies, plugins, build profiles, and project metadata.
The pom.xml Deep Dive
The Project Object Model (POM) is an XML file that drives the entire build lifecycle. Opening it reveals the coordinates you entered, plus default configurations Not complicated — just consistent. But it adds up..
Essential Sections to Know
-
Coordinates & Packaging:
com.company.project my-calculator-app 0.0.1-SNAPSHOT jar -
Properties: Define versions centrally to avoid duplication That's the part that actually makes a difference..
17 17 UTF-8 5.10.0 Always set
maven.compiler.sourceandtargetexplicitly. Eclipse sometimes defaults to 1.5 or 1.8, causing syntax errors if you use modern Java features (likevar, records, or pattern matching) The details matter here.. -
Dependencies: The block where you declare external libraries. Maven downloads them from the Central
Repository on first use, and caches the artifacts locally in ~/.m2/repository so subsequent builds are offline-fast. A typical dependency declaration looks like this:
org.junit.jupiter
junit-jupiter
${junit.version}
test
org.apache.commons
commons-lang3
3.14.0
The scope attribute is what most beginners overlook, and getting it wrong bloats your jar or breaks your tests:
compile(default): available everywhere — main code, test code, and the packaged artifact.test: visible only tosrc/test. JUnit belongs here; it must never leak into production output.provided: expected to be supplied by the runtime container (for example the Servlet API in a WAR deployed to Tomcat).runtime: needed at execution but not at compile time, such as a JDBC driver.
Transitive dependencies arrive automatically: declare commons-lang3 and Maven resolves its own requirements without you listing them. This convenience is also the most common source of version conflicts, when two libraries demand different versions of the same transitive artifact. Maven resolves these by "nearest definition wins," which is deterministic but not always what you want Most people skip this — try not to..
Worth pausing on this one.
mvn dependency:tree
mvn dependency:tree -Dincludes=org.slf4j # narrow the output
For version hygiene across many modules or many libraries, use <dependencyManagement> — it pins versions without actually adding the dependency — or import a BOM (Bill of Materials) such as spring-boot-dependencies or jackson-bom with <scope>import</scope> and <type>pom</type>.
The <build> Section
Dependencies give you libraries; plugins give you behaviour. Every lifecycle phase is bound to plugin goals, most of them implicitly by Maven's packaging defaults. You override or extend them here:
org.apache.maven.plugins
maven-compiler-plugin
3.13.0
17
org.apache.maven.plugins
maven-surefire-plugin
3.2.5
Prefer <release> over the older source/target pair when you can — it cross-compiles against the correct JDK API surface, so you cannot accidentally call a method that exists in 17 but not in 11.
If you want the calculator to be runnable with a plain java -jar, the default maven-jar-plugin output is not enough, because dependencies are omitted. Add a packaging plugin:
maven-shade-plugin— builds a "fat jar" by merging classes and relocating conflicting packages.maven-assembly-plugin— similar, with more control over the descriptor.spring-boot-maven-plugin— a purpose-built variant that produces an executable, nested jar.
With shade configured, target/my-calculator-app-0.0.Even so, 1-SNAPSHOT. jar becomes something you can hand to a user. Without it, it is only a library.
Profiles
Profiles let a single POM describe several environments without forking the file. Activate them by property, by OS, or explicitly with -P:
prod
production
Profiles can also be triggered by the presence of a particular file or by a specific operating system. As an example, a profile that pulls in additional native libraries might be activated when a file named `linux‑native` exists in the project directory:
```xml
linux-native
linux-native
${project.basedir}/native
com.github.native
native-lib
2.4.0
When the file is absent, the profile remains dormant, keeping the build lightweight for developers on other platforms. Likewise, an activation condition based on the OS can select platform‑specific plugins:
windows
Such conditional logic eliminates the need for separate POMs for each environment and lets a single source tree stay portable.
Beyond environment‑specific tweaks, profiles are a convenient place to regroup a set of related configurations. Even so, a common pattern is to bundle all production‑oriented settings — such as a different compiler release, an enabled assembly descriptor, and a signing step — into a profile called release. Activating it with -Prelease during a CI run produces a signed, assembled artifact ready for deployment, while developers working locally can omit the flag and rely on the default configuration Turns out it matters..
Reproducible Builds and the Maven Wrapper
Even though the POM itself is deterministic, the surrounding environment can still introduce variability. cmdbatch file that delegate to a specified Maven version stored in.mvn/wrapper/maven-wrapper.The wrapper consists of a small mvnw script and a mvnw.Even so, jar. Consumers run .Even so, to guarantee that anyone who checks out the code builds exactly the same artifacts, ship the project with the Maven Wrapper. /mvnw clean install without needing a pre‑installed Maven, and the wrapper pins the exact Maven distribution, removing “it works on my machine” discrepancies Small thing, real impact..
CI‑Ready Settings
Continuous integration pipelines benefit from a few additional settings. On top of that, first, store a settings file (settings. That's why xml) in the repository or in the CI environment that configures the remote repository credentials and mirrors, so builds do not fail due to network hiccups. Second, use the -B (batch) mode to make the process non‑interactive, which is essential when no TTY is available. Here's the thing — third, consider disabling tests during a quick verification step with -DskipTests and re‑enable them later with -Dmaven. Now, test. Which means runner. classpath=true if you need to validate a specific test suite.
Aggregating Modules
For larger codebases, a parent POM can declare a list of sub‑modules via the <modules> element. Because of that, each module contributes its own <build> and <dependencies> sections, while the parent can define shared plugin versions, dependency constraints, and repository mirrors. This structure promotes a consistent build across the whole repository and enables a single mvn verify to validate every component at once Worth keeping that in mind..
Release Management
When a project reaches a stable milestone, the Maven Release Plugin streamlines version bumping, SCM tagging, and deployment in one command (`mvn