插件(plugin),每个插件都能实现一个阶段的功能。Maven的核心是生命周期,但是生命周期相当于主要指定了maven命令执行的流程顺序,而没有真正实现流程的功能,功能是有插件来实现的。
比如:compile就是一个插件实现的功能。
编译插件
<build>
<plugins>
<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>
</plugins>
</build>
Tomcat插件
如果使用maven的tomcat插件的话,那么本地则不需要安装tomcat。
第一次使用会从网上下载
首先创建一个maven web工程
然后创建WEB-INF,然后web.xml
最后首页index.jsp
使用tomcat插件运行web工程
默认输入tomcat:run去使用tomcat插件来启动web工程,但是默认的tomcat插件使用的tomcat版本是tomcat6
而目前主流的tomcat,是使用的tomcat7,需要手动配置tomcat插件
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>80</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
使用tomcat7来运行web工程,它的命令是:tomcat7: run(中间有一个空格)