Maven中常用插件的配置

  在Maven项目的pom.xml文件中配置插件信息,使用<build></build>标签

  1、配置JDK版本插件和Tomcat版本插件

 1         <build>
 2                 <!-- 配置JDK版本插件JDK1.7 -->
 3                 <plugins>
 4                     <plugin>
 5                         <groupId>org.apache.maven.plugins</groupId>
 6                         <artifactId>maven-compiler-plugin</artifactId>
 7                         <version>3.5.1</version>  
 8                         <configuration>
 9                             <source>1.7</source>
10                             <target>1.7</target>
11                             <encoding>UTF-8</encoding>
12                         </configuration>
13                     </plugin>
14                     <!-- tomcat7的插件,此插件配置表示启动时使用maven的tomcat插件启动,脱离本地tomcat-->
15                     <plugin>
16                         <groupId>org.apache.tomcat.maven</groupId>
17                         <artifactId>tomcat7-maven-plugin</artifactId>
18                         <version>2.2</version>
19                         <configuration>
20                             <path>/ssm</path>   <!-- 访问的路径,相当于项目名 -->
21                             <port>8888</port>   <!-- 端口号 -->
22                         </configuration>
23                       </plugin>
24                 </plugins>
25             </build>

  2、配置启动本地Tomcat的插件

    不需要手动启动本地Tomcat,在Run As时,选择Maven Build...,输入tomcat7:run即可启动tomcat并运行项目

 1     <!--- 可以使用下面的这个插件启动本地的tomcat服务器 -->
 2                 <plugin>
 3                   <groupId>org.codehaus.cargo</groupId>
 4                   <artifactId>cargo-maven2-plugin</artifactId>
 5                   <version>1.2.3</version>
 6                   <configuration>
 7                       <container>
 8                           <containerId>tomcat7x</containerId>
 9                           <home>D:DevSoftapache-tomcat-7.0.67</home>  <!-- 本地Tomcat安装目录 -->
10                       </container>
11                       <configuration>
12                           <type>existing</type>
13                           <home>D:DevSoftapache-tomcat-7.0.67</home>  <!-- 本地Tomcat安装目录 -->
14                           <!--如果Tomcat端口为默认值8080则不必设置该属性-->
15                           <properties>
16                                 <cargo.servlet.port>8080</cargo.servlet.port>
17                           </properties>
18                       </configuration>
19                   </configuration>
20                   <executions>  
21                       <execution>  
22                           <id>cargo-run</id>  
23                           <phase>install</phase>  
24                           <goals>  
25                               <goal>run</goal>  
26                           </goals>  
27                       </execution>  
28                   </executions>
29               </plugin>

  3、Maven项目中添加jar包

    通过在pom.xml文件中添加jar包依赖

 1     <dependencies>
 2            <dependency>
 3                <groupId>junit</groupId>
 4                <artifactId>junit</artifactId>    <!-- 测试jar包的依赖 -->
 5                <version>4.9</version>
 6                <scope>test</scope>
 7            </dependency>
 8            <dependency>
 9                <groupId>javax.servlet</groupId>
10                <artifactId>servlet-api</artifactId>   <!-- Servlet jar包的依赖 -->
11                <version>2.5</version>
12                <scope>provided</scope>
13            </dependency>
14            <dependency>
15                <groupId>javax.servlet</groupId>
16                <artifactId>jsp-api</artifactId>     <!-- jsp jar包的依赖 -->
17                <version>2.0</version>
18                <scope>provided</scope>
19            </dependency>
20        </dependencies>
原文地址:https://www.cnblogs.com/java-zmj/p/7986905.html