The environment has already been set up, and we'll get it again.
1. Build Javaweb project with Maven
(1), type the following command:
$ MVN archetype:generate-dgroupid=com.holytax.wg-dartifactid=mvnwenapp-darchetypeartifactid= Maven-archetype-webapp-dinteractivemode=false
(2), view the resulting project structure layout:
.| ____mvnwebapp| | ____pom.xml| | ____src| | | ____main| | | | ____resources| | | | ____webapp| | | | | ____index.jsp| | | | | ____web-INF| | | | | | ____web.xml
(3) Modify the Pom.xml update to allow the existing Web. XML to support Servlet 2.5 (the default Servlet2.3 is too old)
Pom.xml
<Projectxmlns= "http://maven.apache.org/POM/4.0.0"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupId>Com.holytax.wg</groupId> <Artifactid>Mvnwenapp</Artifactid> <Packaging>War</Packaging> <version>1.0-snapshot</version> <name>Mvnwenapp Maven Webapp</name> <URL>http://maven.apache.org</URL>
<!-- Set jdk Compiler Level add JDK support -- <Properties> <jdk.version>1.7</jdk.version> </Properties>
<Dependencies> <Dependency> <groupId>Junit</groupId> <Artifactid>Junit</Artifactid> <version>3.8.1</version> <Scope>Test</Scope> </Dependency> </Dependencies> <Build> <Finalname>Mvnwenapp</Finalname>
<Plugins><!--Eclipse Project configures this WTP option in Pom.xml. This option-dwtpversion=2.0 tells Maven to convert the project to Eclipse's Web project (WAR) instead of the default Java project (JAR) instead of a Web project-<Plugin><GroupId>org.apache.maven.plugins</GroupId><Artifactid>maven-eclipse-plugin</Artifactid><Version>2.9</Version><Configuration><!--Always download and attach dependencies source code-<Downloadsources>true</Downloadsources><Downloadjavadocs>false</Downloadjavadocs><!--Avoid type MVN eclipse:eclipse-dwtpversion=2.0-<Wtpversion>2.0</Wtpversion></Configuration></Plugin><!--Set JDK Compiler Level add JDK support-<Plugin><GroupId>org.apache.maven.plugins</GroupId><Artifactid>maven-compiler-plugin</Artifactid><Version>2.3.2</Version><Configuration><Source>${jdk.version}</Source><Target>${jdk.version}</Target></Configuration></Plugin><!--For Maven Tomcat Plugin add Maven's Tomcat plugin declaration-<Plugin><GroupId>org.apache.tomcat.maven</GroupId><Artifactid>tomcat7-maven-plugin</Artifactid><version>2.2</< Span style= "color: #800000;" >version> <> < path>/mvnwenapp </path> </< Span style= "color: #800000;" >configuration> </ plugin> </plugins> </Build> </Project>
Xml
<xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation=" http://java.sun.com/xml/ns/ Java EE http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd " version=" 2.5 " > </ Web-app >
(4), add Eclipse IDE
(5), packaging operation
Generate packaged files under target path
Type the command to run Tomcat
Access results
2. Build Javaweb project with Eclipse
To add a Maven plugin to eclipse:
Open Eclipse----Help----Install New software
Tick the box, and click Next
After downloading, we can build the project.
Select Maven Project
Click Next
Select Next
Fill it out and click Finish.
Project directory Structure:
Load on the Tomcat server, start, access the following
That's it. Wow,,, O (∩_∩) o
Iv. using MAVEN and building Javaweb projects with Eclipse