Use Maven in eclipse to create a WebApp project, choose the following Archtype type:
The resulting project structure is as follows:
The default generated pom.xml files are as follows:
<project xmlns= "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.gof</groupId> <artifactid>base-webapp</ artifactid> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name> Base-webapp Maven webapp</name> <url>http://maven.apache.org</url> <dependencies> <d ependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <versio N>3.8.1</version> <scope>test</scope> </dependency> <!--Servlet--> &L t;dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> &L T;version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <ar tifactid>jsp-api</artifactid> <version>2.1</version> <scope>provided</scope> &L t;/dependency> <dependency> <groupId>javax.servlet</groupId> <artifactid>jstl</art ifactid> <version>1.2</version> </dependency> </dependencies> <build> &
Lt;finalname>base-webapp</finalname> </build> </project>
Note: Sevlet-api and Jsp-api Package Dependency dependency property scope = provided, because the Tomcat container itself provides these two jar packages, so it is only required at compile time. The runtime actually uses a jar package for the Tomcat container. The two jar packages are also not published to Tomcat and are not included in the last generated war package.
The following figure, the publish directory in Eclipse, contains only one of the Dependency-jstl:
The WEB deployment assembly settings are as follows:
Rewrite Web.xml as follows:
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "http://java.sun.com/xml/ns/"
Java ee "
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "
xsi:schemalocation=" http://java.sun.com/ Xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<display-name>base java webapp< /display-name>
<description>a Basic Maven Java Webapp application</description>
< welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Publish the current web app to Tomcat, access the following URL:
http://localhost:8080/base-webapp/
The page is as follows: