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