Configure Pom. XML in Maven packaged as a war package
(1) complete configuration: This is the complete configuration of servlet, similar to others.
<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/xsd/maven-4.0.0.xsd"> <modelversion> 4.0.0 </modelversion> <groupid> COM. testmy </groupid> <artifactid> testmy </artifactid> <version> 0.0.1-Snapshot </version> <packaging> war </packaging> <dependencies> <dependency> <groupid> J Avax. servlet </groupid> <artifactid> javax. servlet-API </artifactid> <version> 3.0.1 </version> <scope> provided </scope> </dependency> <groupid> javax. servlet. JSP </groupid> <artifactid> JSP-API </artifactid> <version> 2.2 </version> <scope> provided </scope> </dependency> </dependencies> <build> <plugins> <! -- Web. XML is missing and <failonmissingwebxml> is set to true --> <plugin> <groupid> org. apache. maven. plugins </groupid> <artifactid> Maven-war-plugin </artifactid> <version> 2.6 </version> <configuration> <failonmissingwebxml> false </failonmissingwebxml> </configuration> </plugin> <! -- In the project pom. specify the JDK version in XML --> <plugin> <groupid> Org. apache. maven. plugins </groupid> <artifactid> Maven-compiler-plugin </artifactid> <version> 3.1 </version> <configuration> <source> 1.7 </source> <target> 1.7 </Target> </configuration> </plugin> </plugins> </build> </Project>
(2) When an error is reported in the project:Web. XML is missing and <failonmissingwebxml> is set to true
You need to add the following configuration in POM. xml:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin>
(3) In the project, specify the JDK version in POM. xml. By default, the JDK version in Maven is 1.5, which does not meet the requirements. In case of any errors, You need to modify the JDK version to use a higher version.
Add the following configurations:
<! -- In the project pom. specify the JDK version in XML --> <plugin> <groupid> Org. apache. maven. plugins </groupid> <artifactid> Maven-compiler-plugin </artifactid> <version> 3.1 </version> <configuration> <source> 1.7 </source> <target> 1.7 </Target> </configuration> </plugin>
After the preceding modification, the package project is a war package.
Configure Pom. XML for the war package in Maven