Header Ads Widget

Responsive Advertisement

Maven Project Guide


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

  1. Open Eclipse.
  2. Navigate to File > New > Other.
  3. In the wizard, type Maven in the search bar, and select Maven Project.
  4. Click Next.

Step 2: Configure Maven Project

  1. Choose the default workspace location or select a custom one.
  2. Check or uncheck Create a simple project (skip archetype selection).

ü  If unchecked, you'll be prompted to select a Maven archetype (template).

  1. Click Next.

Step 3: Choose Archetype

  1. Select a Maven archetype (e.g., maven-archetype-quickstart for a simple Java project).
  2. Click Next.

Step 4: Enter Group ID and Artifact ID

  1. 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).

  1. Optionally, configure Version and Package (the default version is 1.0-SNAPSHOT).
  2. Click Finish.

Step 5: Project Structure

  1. 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

  1. Open the pom.xml file to add dependencies.
  2. Inside <dependencies>, you can add libraries like this:

Xml

<dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-core</artifactId>

    <version>5.3.10</version>

</dependency>

 

  1. Save the pom.xml and Maven will download the necessary dependencies.

Step 7: Build and Run Maven Project

  1. Right-click on the project, select Run As > Maven Build.
  2. In the "Goals" field, enter clean install to clean and install the project.
  3. 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

  1. Open IntelliJ IDEA.
  2. Go to File > New > Project.
  3. In the "New Project" wizard, select Maven from the list on the left.
  4. Click Next.

Step 2: Configure Maven Project

  1. 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.
  2. Click Next.

Step 3: Enter Project Information

  1. Enter GroupId and ArtifactId (same as in Eclipse).

ü  Example: GroupId: com.example, ArtifactId: myapp.

  1. Specify the Version and Package if necessary.
  2. Click Finish.

Step 4: Project Structure

  1. 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

  1. Open pom.xml and navigate to the dependencies section.
  2. Add any Maven dependencies, for example:

Xml

<dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-core</artifactId>

    <version>5.3.10</version>

</dependency>

 

  1. IntelliJ will automatically download the dependencies and add them to your project.

Step 6: Build the Maven Project

  1. In the Maven tool window (usually on the right side of the IDE), expand the project, and click the lifecycle node.
  2. Double-click on install to build the project.
  3. IntelliJ will run Maven’s build lifecycle (clean, compile, test, package, etc.).

Step 7: Running the Application

  1. You can run your application directly by right-clicking the main class or using the Run button.
  2. 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

Ø  Insertion Sort

Ø  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 country

Ø  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:

Ø  Design pattern

Ø  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

Ø  Java Design Pattern

Ø  Passive Infrared (PIR) sensors understand and implementation by java



  

Maven Project Guide
Maven Project Guide



Post a Comment

0 Comments