标题:
java 架构探险(3)添加Java Web的Maven依赖
[打印本页]
作者:
look_w
时间:
2018-12-14 19:03
标题:
java 架构探险(3)添加Java Web的Maven依赖
五,添加Java Web的Maven依赖
Web项目需要打包成war,需要在pom.xml中配置packaging为war(默认为jar)
1
<!--配置项目的打包方式,默认jar-->
<packaging>war</packaging>
1
2
添加java Web所需Servlet,JSP,JSTL等依赖,完整maven配置pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>org.smart4j</groupId>
<artifactId>chapter</artifactId>
<version>1.0.0</version>
<!--配置项目的打包方式,默认jar-->
<packaging>war</packaging>
<!--1,(必须)需要统一源码编码方式,否则Maven编译源码时会出现警告,选用UTF-8-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!--Servlet provided:只参与编译,不参与打包(tomcat中也有servlet-api包,会冲突)-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!--JSP provided:只参与编译,不参与打包-->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!--JSTL runtime:运行时生效,不参与编译-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--2,(必须)统一源代码编译输出的JDK版本,本例使用JDK 1.6-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!--3,(可选)使用Maven打包时可跳过单元测试-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!--通过Maven将应用不是到Tomcat中-->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.artifactId}</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0