Maven的核心仅仅定义了抽象的生命周期,具体的任务都是交由插件完成的。每个插件都能实现一个功能,每个功能就是一个插件目标。Maven的生命周期与插件目标相互绑定,以完成某个具体的构建任务。
例如compile就是插件maven-compiler-plugin的一个插件目标
1、编译插件
<!-- 编译插件,指定编译用的JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- 源码版本 -->
<source>1.7</source>
<!-- 编译目标版本 -->
<target>1.7</target>
<!-- 指定编码 -->
<encoding>UTF-8</encoding>
</configuration>
</plugin>
修改配置文件后,在工程上点击右键选择maven→update project configration
2、tomcat插件
如果使用maven的tomcat插件的话,那么本地则不需要安装tomcat。
使用maven创建一个web工程
第一步:不选用骨架
第二步:将打包方式选择为war
第三步:工程创建成功。在工程中添加web.xml(去其他地方copy一份就行)
第四步:在pom.xml文件中添加tomcat插件
<!-- 配置tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<!-- 访问端口 -->
<port>8080</port>
<!-- 访问路径 -->
<path>/</path>
<!-- 编码 -->
<uriEncoding>UTF-8</uriEncoding>
</configuration>
</plugin>
第五步:使用tomcat插件运行web工程
默认输入tomcat:run去使用tomcat插件来启动web工程,但是默认的tomcat插件使用的tomcat版本是tomcat6
tomcat:run 运行tomcat6(默认)
tomcat7:run 运行tomcat7(推荐,但是需要添加插件)