对象已移动

可在此处找到该文档 Getting Started with Apache Maven (JAVA/J2EE) – New Self New Life
New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Getting Started with Apache Maven (JAVA/J2EE)

by admin
4 years ago
in Softwares
Getting Started with Apache Maven (JAVA/J2EE)
Share on FacebookShare on Twitter


At the moment we’re going to take a look at the Apache Maven mission administration software for Java/2EE builds. We’ll talk about how you can set up, configure, and create a mission and Alumni servlet. We may even go over some plugins for Apache Maven as nicely. There’s a lot to unpack, so let’s dive proper in!

Apache Maven is a construct, or whole mission administration software that scores wins over its predecessors, comparable to ANT for Java builds, with the next benefits/areas that it excels in:

  • Helpful when A number of JAR Information are Required for a Construct
  • Resolving Recursive Dependencies Throughout Construct Time
  • Creating Mission Buildings which can be Standardized
  • Constructing, Publishing and Deployment of Purposes
  • Helps Lifecycle of an Software together with Plugins

For the aim of this Apache Maven tutorial, I’ve created an alumni mission that may be a Dynamic Internet Archive with a Servlet that claims “Hi there, Alumni” within the shopper’s browser. The next is an inventory of installations required for this mission:

INSTALLATIONS REQUIRED

  • Apache Maven 3.2.5
  • Apache Tomcat 8.0.9
  • JDK 1.7.0 / JRE 1.7.0
  • Notepad++ 6.6.7

Apache Maven Fundamentals: The right way to Setup Maven

To start, obtain the newest model of Apache Maven (3.2.5 on the time of this writing) from the Apache Maven obtain web page: http://maven.apache.org/obtain.cgi

Subsequent, Set the trail variables for M2 and M2_HOME. Set your M2_HOME atmosphere variable to level to the basis of the Apache Maven set up. Additionally, the M2 atmosphere variable might be pointing to the bin folder beneath the Apache Maven set up. For instance, you probably have put in Apache Maven beneath d:apache-maven-3.2.5 – you would need to set the variables as follows:

set M2_HOME= d:apache-maven-3.2.5
set M2= d:apache-maven-3.2.5bin

You should moreover set Maven in your path as follows.
set PATH=%PATH%;%M2%

The right way to Configure Apache Maven and Create a Mission

After you may have arrange your variables, the following step is to run the mvn archetype:generate command from the place the place you need to create an online mission. Begin off with this command to obtain the entire templates from the Web. This must be used initially in order that the entire mission templates may be downloaded to the native system. You’ll be prompted on the finish of this command’s “profitable execution” for a quantity. Enter the quantity 529, which is the default used for ‘maven-archetype-webapp’. Just be sure you have an Web connection; in any other case, you’ll not see the entire archetype listings. Maven Archetype is a templating toolkit that’s offered together with Maven.

Maven Archtypes

Creating an Alumni Servlet with Apache Maven

Add a folder ‘java’ beneath ‘srcmain’ earlier than we will code our Java Servlet. Underneath predominant add the folders ‘me’, adopted by ‘sumithpuri’ adopted by ‘maven’ – every beneath the opposite; in order that the listing construction appears to be like like this:

Alumni-Servlet-Java

Now, create the Java Servlet supply file AlumniServlet.java utilizing Notepad++ as follows:

Create-Java-Servlet-Maven

If we attempt to construct the mission utilizing ‘mvn compiler:compile’, we are going to get the next errors, as a result of we now have not added the dependent JAR information for Java Servlets.

Compiling-Java-Servlet-Error-Maven

The subsequent step we have to take is so as to add the dependent JARs in order that the mission can compile. We will achieve this within the pom.xml, as proven under. The reason for the way Maven will obtain this JAR to the native repository and the main points of the POM (Mission Object Mannequin) are offered later on this article.

Adding-JARs-Java-Servlet-Maven

As soon as we now have added our dependent JARs to the mission, we will lastly use ‘mvn compiler:compile’ to construct or compile the net utility.

Build-Java-Web-App-Maven

Packaging and Deploying an Alumni Mission in Apache Maven

Now that we now have configured our Apache Maven arrange, created our Java Servlet, and constructed our mission, we will lastly bundle and deploy our Alumni Mission. To do that, we should modify the net.xml file so as to add our servlet utilizing the next configuration:

Maven-Java-XML-Alumni-Srvlet

Subsequent, use the command ‘mvn battle:battle’ to bundle the net utility, as proven under:

Packaging-Java-Web-Apps-Maven-Apache

To complete packaging and deploying the Alumni Mission, drop the bundle beneath the Apache Tomcat ‘webapps’ folder and sort the url http://localhost:8080/alumni into the browser to see the next output:

Maven-Alumni-Project-Browser

NOTE: Be sure to rename the default index.JSP file to index.BKP with a view to render the Servlet output.

You might obtain the alumni.zip that additionally accommodates the alumni.battle beneath goal folder to do this out your self.

Apache Maven Principle: Necessary Ideas To Know

Maven coordinates serve to establish tasks, dependencies and plugins throughout the Mission Object Mannequin (POM). The next coordinates are required for each mission, so you will need to know their that means and what they’re used for:

  • groupId: The title with which we will confer with a gaggle of tasks. This reference factors to a repository listing that makes use of a tree construction. An instance of a groupid may very well be org.apache.commons.
  • artifactId: ‘alumni_project artifactId’ can be the title of the JAR or WAR we are going to create.
  • model: ‘alumni model’, can be the model quantity of the present mission bundle.

Understanding the Maven Lifecycle

A very powerful lifecycle phases or phases for a Maven mission embody the next.

  • validate: Validates if the mission co-ordinates and pom.xml are legitimate, else it generates error.
  • compile: Compiles the mission and generates any error it can not compile.
  • take a look at: Unit Checks the code and doesn’t require that the code to be packaged.
  • bundle: Packages and generate the artifact (comparable to JARs).
  • set up: Installs the generated artifact, comparable to JAR, within the native repository.

Maven Plugins and the Maven Repository (Structure)

Maven works within the type of plugins and follows the final format of: mvn plugin:purpose

A few of the plugins embody jar, compiler, and surefire. An instance of a Maven command can be: mvn compiler:compile

Maven follows a two repository mannequin, whereby it maintains an area repository (which is created once you execute the primary Maven command). It downloads dependencies from the distant repository onto this native repository after which builds tasks. The structure appears to be like like the next:

Maven-Repository-Model

  • Maven Mission is compiled; It checks within the native repository for dependencies.
  • If dependencies don’t exist, Maven downloads them from the distant repository.
  • As soon as dependencies are downloaded they’re put in within the native repository.
  • As soon as all dependencies are met Maven compiles the code and the mission.

Apache Maven Mission Object Mannequin (POM)

Maven is ready to obtain dependency administration via the existence of Mission Object Mannequin or pom.xml information inside every of the modules. At every module degree, we will present pom.xml, which accommodates the construct atmosphere info, construct settings info, dependency relationships between POM’s and common mission info. Additionally, there’s a idea of inheritance and efficient POM (the place the efficient POM is a results of the inheritance hierarchy).

Maven-Sample-POM-XML

[A Sample POM.xml ]

Situated contained in the Maven set up is a Tremendous POM (pom.xml), often situated within the maven-model-builder-.jar information, which is discovered beneath the %M2_HOMEpercentlib folders. This accommodates the main points of all different modules’ POM inherits from. This additionally accommodates the placement of the distant repository, which is by default https://repo.maven.apache.org/maven2. It often has 4 predominant sections: central repository particulars, plugin repository particulars, construct particulars, and plugin administration particulars.

In conclusion, Maven supplies a easy and extensible option to compile, construct, and deploy purposes and permits us to handle the entire construct life-cycle of our purposes.



Source link

Tags: ApacheJAVAJ2EEMavenStarted
Previous Post

CSS Smooth Scroll

Next Post

Make way for our newest Noisemaker – Rishabh Pant

Related Posts

User Guide for Odoo MultiChannel Email Marketing
Softwares

User Guide for Odoo MultiChannel Email Marketing

by admin
July 6, 2025
Avoid these common platform engineering mistakes
Softwares

Avoid these common platform engineering mistakes

by admin
July 4, 2025
Meta slams ‘incorrect and unlawful’ EU DMA ruling
Softwares

Meta slams ‘incorrect and unlawful’ EU DMA ruling

by admin
July 3, 2025
Best Practices, Tools, xUnit, and NUnit Framework
Softwares

Best Practices, Tools, xUnit, and NUnit Framework

by admin
July 1, 2025
Start up crash fix – Vivaldi iOS Browser snapshot 3737.4
Softwares

Start up crash fix – Vivaldi iOS Browser snapshot 3737.4

by admin
June 30, 2025
Next Post
Make way for our newest Noisemaker – Rishabh Pant

Make way for our newest Noisemaker – Rishabh Pant

Best Coding Practices For Rest API Design

Best Coding Practices For Rest API Design

  • Trending
  • Comments
  • Latest
All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

All the glamorous celebrity looks from the Jeff Bezos, Lauren Sánchez wedding – National

June 28, 2025
‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

‘America is back’: Foo Fighters show hits 100% capacity at Madison Square Garden – National

June 22, 2021
How to integrate Odoo with ReactJs frontend

How to integrate Odoo with ReactJs frontend

October 7, 2024
Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

Kanye West entry visa revoked by Australia after ‘Heil Hitler’ song release – National

July 3, 2025
Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

Indiana Evans: What happened to the H2O Australian actress Indiana Evans and what is she doing now? | Explainer

December 7, 2024
Jane Withers, child actor and commercial star, dies at 95 – National

Jane Withers, child actor and commercial star, dies at 95 – National

August 10, 2021
18 Best Political Series on Netflix, Ranked

18 Best Political Series on Netflix, Ranked

March 25, 2025
Games teach kids climate action

Games teach kids climate action

January 23, 2024
Hip-Hop Artists We Lost in 2025

Hip-Hop Artists We Lost in 2025

July 6, 2025
$49 Align Styles and More Steals Starting at $19

$49 Align Styles and More Steals Starting at $19

July 6, 2025
Queen Mary of Denmark stuns in the staple of the summer

Queen Mary of Denmark stuns in the staple of the summer

July 6, 2025
Countdown Episode 5 Release Date, Time, Where to Watch

Countdown Episode 5 Release Date, Time, Where to Watch

July 6, 2025
App Cast: Android’s Rival To Apple’s Handoff Feature Spotted

App Cast: Android’s Rival To Apple’s Handoff Feature Spotted

July 6, 2025
Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

Latest Sales Data Reveal Clear Winners And Losers in a Messy EV Market

July 5, 2025
Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

Critics And Fans Disagree On Netflix’s Controversial Fantasy Show With Near-Perfect RT Score

July 5, 2025
Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

Nip/Tuck Star Julian McMahon Dead at 56 After Private Cancer Battle

July 5, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Hip-Hop Artists We Lost in 2025
  • $49 Align Styles and More Steals Starting at $19
  • Queen Mary of Denmark stuns in the staple of the summer
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

New Self New Life