Java Development Engineer (Web orientation)-Introduction to 01.Java Web Development-4th chapter. Maven

Source: Internet
Author: User

4th Chapter--mavenmaven Combat

Java Web deployment of the app:

Manual type:

Compilation: JAVAC-CP $CATALINA _home/lib/servlet-api.jar Web-inf/classes/package/noodlesservlet.java

Package: Jar CVF Restaurant.war.

Mobile: MV Restaurant.war .../webapps/

When a project is complex: for example, there are many project files--Ides such as Eclipse--

IDE type: (e.g. Eclipse)

Download third-party dependency packages, where to download?

How is the directory structure set?

Compile, test, package, release, how is the build process unified?

Project code sharing and dependencies, how to do?

How is the version managed?

--common tools to solve the above problems

Maven:

Project building and dependency management tools for Java Web

Apache Foundation, open Source, written by Java

Reasons to choose Maven:

The directory structure is defined by default (Convention/Convention Precedence principle)

Provides a three-party-dependent management solution to dependent maintenance issues

Provides a consistent approach to project building management-reduces build effort and reduces learning costs

Plug-in architecture, a large number of reusable plugins

It's easy to integrate the IDE

MAVEN Installation:

Dependent JDK

Official website: http://maven.apache.org/

$ Brew Install Maven3

To configure environment variables:

M2_home=/dir to maven/

Path= $PATH: $M 2_home/bin

The configuration that MAVEN uses when building the project: Pom.xml

MAVEN Project coordinates: locating unique items (not repeatable)

GroupId: Organization

Artifactid: Project identifier

Version: Revision number (i.e. <version>1.0.0-SNAPSHOT</version>) (SNAPSHOT as development version)

Other properties:

Packaging: Type, i.e. war

Dependencies: Dependent projects

Basic command:

MVN archetype:generate: Building a project with a template

MVN compile: Compiling

MVN Test: Unit Testing

MVN Package: Pack War

MVN Deploy: Deployment

MVN site: Generate project-related sites, online documentation, etc.

MVN Clean: Cleanup

MVN Install: Installs the package to the local warehouse, can depend on it

Tomcat plugin: Tomcat's official MAVEN plugin: Implementing a tomcat embedded in Maven

MVN HELP:DESCRIBE-DPLUGIN=TOMCAT7

Common commands:

MVN Tomcat7:run: Launch an embedded tomcat instance

mvn Tomcat7:deploy; mvn Tomcat7:undeploy, etc.

How to manage a Tomcat project using Maven:

mkdir Creating a Directory

MVN archetype:generate-dgroupid=com.netease.restaurant-dartifactid=restaurant-dpackage=com.netease-dversion= 1.0.0-snapshot-darchetypeartifactid=maven-archetype-webapp Creating a Project

The resulting directory structure:

Generate Pom.xml:

Lack of dependency on servlet: Add dependency in <dependencies></dependencies>

Configuration plugin: Compiler plugin and tomcat plugin

Create the Java/com/netease folder under Main and copy the Java file from the previous lesson to the folder

Copy the static resources to the WebApp folder

Replace the Web. XML under Web-inf with the Web. Xml that was written last lesson

Delete the index.jsp under WebApp

Run Project: (note, run in restaurant directory, otherwise error)

MVN Tomcat7:run

And it is running

open another Terminal tab and Curl Http://localhost:8080/Restaurant/noodles; it works.

Java Development Engineer (Web orientation)-Introduction to 01.Java Web Development-4th chapter. Maven

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.