Maven Project Guide: Step-by-Step for Eclipse and
IntelliJ IDEA
Below are detailed instructions to create and manage Maven
projects in both Eclipse and IntelliJ IDEA.
1. Eclipse Maven Project Setup
Prerequisites:
Ø Eclipse
IDE installed
Ø Maven
integration for Eclipse (M2E plugin), which comes pre-installed in modern
Eclipse versions
Steps to Create a Maven Project in Eclipse:
Step 1: Create a New Maven Project
- Open
Eclipse.
- Navigate
to File > New > Other.
- In
the wizard, type Maven in the search bar, and select Maven Project.
- Click
Next.
Step 2: Configure Maven Project
- Choose
the default workspace location or select a custom one.
- Check
or uncheck Create a simple project (skip archetype selection).
ü
If unchecked, you'll be prompted to select a
Maven archetype (template).
- Click
Next.
Step 3: Choose Archetype
- Select
a Maven archetype (e.g., maven-archetype-quickstart for a simple Java
project).
- Click
Next.
Step 4: Enter Group ID and Artifact ID
- Fill
in the required fields:
ü
Group ID: A unique identifier for your
project (usually in reverse domain notation, e.g., com.example).
ü
Artifact ID: The name of your project
(e.g., myapp).
- Optionally,
configure Version and Package (the default version is 1.0-SNAPSHOT).
- Click Finish.
Step 5: Project Structure
- Eclipse
will generate the project structure based on the archetype you selected.
ü
src/main/java: Source files
ü
src/test/java: Test files
ü
pom.xml: Maven configuration file where
dependencies are declared
Step 6: Manage Dependencies
- Open
the pom.xml file to add dependencies.
- Inside
<dependencies>, you can add libraries like this:
Xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId> <version>5.3.10</version> </dependency> |
- Save
the pom.xml and Maven will download the necessary dependencies.
Step 7: Build and Run Maven Project
- Right-click
on the project, select Run As > Maven Build.
- In
the "Goals" field, enter clean install to clean and install the
project.
- Click
Run.
Step 8: More Details of Maven Project
https://drive.google.com/file/d/0B7xaspetzd9-dGZXQjh1ZXpWT2c/view?usp=sharing
2. IntelliJ IDEA Maven Project Setup
Prerequisites:
Ø IntelliJ
IDEA installed (Community or Ultimate Edition)
Ø Maven
is built into IntelliJ IDEA, so no additional plugins are required.
Steps to Create a Maven Project in IntelliJ IDEA:
Step 1: Create a New Maven Project
- Open
IntelliJ IDEA.
- Go to
File > New > Project.
- In
the "New Project" wizard, select Maven from the list on
the left.
- Click
Next.
Step 2: Configure Maven Project
- Uncheck
Create from archetype if you want to manually configure the
project.
- If
you check this option, select a suitable archetype, such as maven-archetype-quickstart.
- Click Next.
Step 3: Enter Project Information
- Enter
GroupId and ArtifactId (same as in Eclipse).
ü
Example: GroupId: com.example, ArtifactId: myapp.
- Specify
the Version and Package if necessary.
- Click
Finish.
Step 4: Project Structure
- IntelliJ
will create the Maven project structure:
ü
src/main/java: Java source files
ü
src/test/java: Test files
ü
pom.xml: Configuration file for Maven
Step 5: Adding Dependencies
- Open pom.xml
and navigate to the dependencies section.
- Add
any Maven dependencies, for example:
Xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId> <version>5.3.10</version> </dependency> |
- IntelliJ
will automatically download the dependencies and add them to your project.
Step 6: Build the Maven Project
- In
the Maven tool window (usually on the right side of the IDE),
expand the project, and click the lifecycle node.
- Double-click
on install to build the project.
- IntelliJ
will run Maven’s build lifecycle (clean, compile, test, package, etc.).
Step 7: Running the Application
- You
can run your application directly by right-clicking the main class or
using the Run button.
- Alternatively,
you can run specific Maven goals like mvn clean install from the Maven
tool window or the terminal.
Additional Tips for Both Eclipse and IntelliJ
Ø Importing
an Existing Maven Project:
ü
In Eclipse: Go to File > Import
> Existing Maven Projects and select the project directory.
ü
In IntelliJ: Go to File > New
> Project from Existing Sources, select the project directory, and
follow the steps to import it as a Maven project.
Ø Changing
Java Version:
ü
In both IDEs, you can specify the Java version
by modifying the <properties> section in pom.xml:
Xml
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> </properties> |
Ø Managing
Plugins:
ü
You can add Maven plugins in the <build>
section of the pom.xml to customize your build process (e.g., maven-compiler-plugin
for Java compilation).
Ø Executing
Maven Commands:
ü
In Eclipse, right-click the project > Run
As > Maven Build..., and specify goals (e.g., clean install).
ü In IntelliJ, access the Maven tool window and choose the preferred Maven goals, such as clean, install, or test.
This guide will help you create, configure, and manage Maven
projects using either Eclipse or IntelliJ IDEA efficiently.
1.
Creating and Importing a Maven Project
a.
We will initiate a Spring Boot project using http://start.spring.io.
b.
This project will then be imported into Eclipse or
IntelliJ as a Maven Project.
2.
Understanding the pom.xml Project Object
Model
a.
Assigning a name to the project.
b.
Specifying dependencies.
3.
Maven Build Life Cycle
a.
Execute "mvn clean install."
b.
The Maven Build Life Cycle consists of the
following phases: Validate > Compile > Test > Package > Integration
Test > Verify > Install > Deploy.
c.
The predefined folder structure takes precedence
over configuration.
i.
Source Code
a.
${basedir}/src/main/java
b.
${basedir}/src/main/resources
ii.
Test Code
a.
${basedir}/src/test
4.
How Maven Operates
a.
Local Repository
b.
Maven Repository
i.
This repository holds all versions of
dependencies, such as JUnit 4.2, 4.3, and 4.4.
ii.
The command "mvn install" copies the
generated jar file to the local Maven repository, which is a temporary folder
on my machine for storing these files.
5.
Step 5: Key Maven Commands
a.
mvn --version
b.
mvn compile (compiles the source files)
c.
mvn test-compile (compiles test files) - note
that this also compiles the source files.
d.
mvn clean - removes the target directory.
e.
mvn test - executes unit tests.
f.
mvn package - generates the jar file.
g.
help:effective-settings
h.
help:effective-pom
i.
dependency:tree
j.
dependency:sources
k.
–debug
For Tools information, visit:
Ø Generate a Token in Sonatype Nexus & Use It in Maven & Jenkins
Ø
CI/CD
Pipeline in Jenkins: Staging & Production Artifact Flow in java app
Ø
Master
in CI/CD pipeline using Maven with java
For More sort information, visit:
Ø
Selection
Sort with iteration wise per step
Ø
Bubble
Sort with each iteration how it is work
Ø
Merge
sort of Each step how it is working
Ø
Quick
Sort per iteration what happen
Ø
Sorting
Of a list multiple attribute wise two technique
Ø
Seat
Arrangement in Sorting Order Like 1A-1E, 3C-3G etc
Ø
How
to sort 10 billion numbers
Ø
Merge
Sort simple under standing
For Math information, visit:
Ø
Calculating
the area of a triangle
Ø
The
method for calculating the area of a rectangle in Java
Ø
The value of π =
3.14159 in java [Click
Here]
For Design information, visit:
Ø
Mastering
Design Patterns Practical Implementation Tips
Ø
How
to draw sequence diagram and other diagrams using plantuml
Ø
Time
Analysis for Congested Routes Using Shortest Path Algorithms
Ø Passive
Infrared (PIR) sensors understand and implementation by java
Maven Project Guide |
0 Comments