0% found this document useful (0 votes)
39 views

Maven Repository

About maven repository , maven pom.xml ,and how to convert web dynamic project into maven in Eclipse IDE.

Uploaded by

Khushi Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Maven Repository

About maven repository , maven pom.xml ,and how to convert web dynamic project into maven in Eclipse IDE.

Uploaded by

Khushi Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Maven

Maven is a powerful project management and comprehension tool based on the Project Object
Model (POM). It is widely used in Java development to simplify and streamline the process of
building, managing dependencies, and generating documentation for projects. Maven
significantly enhances the capabilities of traditional build tools like ANT by providing a more
advanced and integrated approach to project management.

What is Maven Repository?


A Maven repository is a central location where Maven-based project artifacts, such as JAR files
and metadata, are stored and managed. These repositories play a critical role in the dependency
management and build processes of Maven projects. Maven repositories allow developers to
share and reuse artifacts, thereby promoting consistency and efficiency in software development.
Maven uses three primary types of repositories:
1. Local Repository - The local repository is a directory on the developer's machine where Maven
stores artifacts that have been downloaded or created by the build process. By default, this
repository is located at `${user.home}/.m2/repository` (e.g., `C:\Users\username\.m2\repository`
on Windows). When Maven needs a dependency, it first checks this local repository to see if the
dependency is already available. If it is, Maven uses it directly, which speeds up the build process
and reduces network traffic.
2. Central Repository - The central repository is a global repository maintained by the Maven
community. It contains a vast collection of commonly used libraries and project dependencies.
When a dependency is not found in the local repository, Maven queries the central repository to
download the required artifact. This repository is accessible online at [Maven
Central](https://search.maven.org/), and it serves as the default source for resolving dependencies
when no other repository is specified.
3. Remote Repository - Remote repositories are additional repositories specified by the user in
the POM file or the settings.xml configuration. These repositories can be hosted on web servers
and are often used to store internal company artifacts or third-party libraries not available in the
central repository. When Maven cannot find a dependency in the local or central repositories, it
searches these specified remote repositories. This flexibility allows organizations to maintain their
own repositories and manage proprietary or specialized libraries.
What is Maven Life Cycle?
A Maven build lifecycle is a sequence of phases, each phase consisting of a set of goals that are
executed in a predefined order to accomplish specific tasks during the build process. Maven
defines three standard lifecycles:
1. Clean Lifecycle - The clean lifecycle is used to clean the project and remove all files generated
by the previous builds. It typically involves the three phases - pre-clean , clean and post-clean.
Command: `mvn clean`
2. Default (or Build) Lifecycle - The default lifecycle handles the project's deployment. This
lifecycle is the main lifecycle in Maven. Some of the phases are :
o validate: Validates the project is correct and all necessary information is available.
o initialize: Initializes build state, such as setting properties.
o compile: Compiles the source code of the project.
o package: Packages the compiled code into a distributable format, such as a JAR or WAR
file.
o verify: Runs any checks to verify the package is valid and meets quality criteria.
o install: Installs the package into the local repository, making it available for other projects
on the local machine.
o deploy: Copies the final package to the remote repository for sharing with other developers
and projects.
3. Site Lifecycle - The site lifecycle is used to create project documentation. This lifecycle consists
four phases: pre-site , site , post-site , site-deploy.

What is Maven pom.xml file?


The `pom.xml` file, or Project Object Model, is the cornerstone of a Maven project. It contains
the necessary configuration details and instructions for building and managing a project. The file
is written in XML and includes various elements that define the project's structure, dependencies,
and build process.
Sample pom.xml file :

Elements of pom.xml are :

1. project - The root element of the `pom.xml` file. It encompasses all other elements and
configurations within the file.
2. modelVersion - Specifies the version of the POM model being used. For projects using
Maven 2 and Maven 3, this is set to "4.0.0".
3. groupId - A unique identifier for the project group, usually resembling the root Java
package name of the project. It helps in organizing and identifying related projects within
a larger ecosystem.
4. artifactId - The name of the project or the artifact that is being built. This is a unique
identifier within the groupId and is typically the same as the project's directory name.
5. version - Indicates the version of the project. This is crucial for managing different releases
of the project, allowing developers to specify and manage versioning easily.
6. dependencies - Defines external libraries and modules that the project depends on. Each
dependency includes its groupId, artifactId, and version, ensuring that Maven can locate
and download the necessary libraries.
7. Build - Contains configurations related to the build process, such as specifying plugins
and their configurations. Plugins are tools that add additional capabilities to the build
process, such as compiling code or packaging the application.
8. Repositories - Specifies remote repositories where Maven can find additional
dependencies that are not available in the central repository. This is useful for integrating
third-party libraries and internal corporate libraries.
9. properties - Defines custom properties that can be used throughout the `pom.xml` file.
This allows for easier management of values that are reused in multiple places within the
file, such as version numbers or directory paths.

How to convert web dynamic project into maven in Eclipse IDE?


1. Importing the WAR file into Eclipse
Step 1: Go to File > Import.
Step 2 : Select WAR > click Next.
Step 3 : Click Finish.

2. Configure Server , Java Build Path and Targeted Runtime


Step 1 : Right Click on Project > Select Properties.
Step 2 : Go to Server > Add WildFly Server > Click Apply.

Step 3 : Go to targeted runtime > Check WildFly runtime > Apply.


Step 4 : Go to Java Build Path > Select All > Apply.

Step 5 : Apply and Close.

3. Converting Web dynamic project to maven using Eclipse


Step 1: Select your Dynamic Web Project and hit the Right Click button.

Step 2: Now click on the Configure » Covert to Maven Project.


Step 3: After clicking on Convert to Maven Project, a new pop-up window will open. It will
show the configuration of pom.xml.
Step 4: Hit the Finish button. Finally, your Dynamic Web Project successfully converted
into Maven Project.

Step 5: Project structure of Maven Project.

Step 6: Done.
4. Clean and rebuild maven project
Step 1: Click on Project menu in eclipse.
Step 2 : Clean > Select Project > Clean.

Using Maven Clean


Step 1 : Right Click on Project
Step 2 : Run As > Maven clean

5. Updating Maven project in Eclipse IDE


Step 1: Right Click on the project
Step 2 : Go to Maven option
Step 3 : Update Project (Alt + F5)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy