maven将web项目打成war到指定目录之下

来源:互联网 发布:华为网络管理平台价格 编辑:程序博客网 时间:2024/06/05 19:01

首先在pom.xml中对需要的几个maven插件进行配置,配置如下:  
<!-- 下面进行maven项目的打包配置  --><build><plugins><!-- 用于maven编译的plugin   --> <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.1</version><configuration><fork>true</fork><defaultLibBundDir>lib</defaultLibBundDir><source>1.8</source><target>1.8</target><encoding>UTF-8</encoding> <!--如果配置了JAVA_HOME,下面应该可以不用配                     <executable>E:\JDK\jdk1.8\bin\javac.exe</executable> --></configuration></plugin>  <!-- resource插件   -->            <plugin>                  <groupId>org.apache.maven.plugins</groupId>                  <artifactId>maven-resources-plugin</artifactId>                  <version>2.7</version>                 <configuration>                <encoding>UTF-8</encoding>                </configuration>             </plugin>   <!-- 用于拷贝maven依赖的plugin  -->            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-dependency-plugin</artifactId>                <version>2.10</version>                <executions>                    <execution>                        <id>copy-war</id>                        <phase>package</phase>                        <goals>                            <goal>copy</goal>                        </goals>                        <configuration>                        <artifactItems>                        <artifactItem>                         <groupId>${project.groupId}</groupId>                                     <artifactId>${project.artifactId}</artifactId>                                                                       <type>${project.packaging}</type>                         </artifactItem>                                                </artifactItems>                   <!--   将打好的war包拷贝到指定目录之下,我这里直接到tomcat下 -->                            <outputDirectory>F:/tomcat/apache-tomcat-7.0.70/webapps</outputDirectory>                           <includes>                           <include>*.war</include>                           </includes>                        </configuration>                    </execution>                </executions>            </plugin>             <!--  打war包配置pligin 默认是打包到target目录下-->            <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>2.6</version><configuration><!-- war包不要带版本号,默认是有的 --><warName>${project.artifactId}</warName><webResources><resource> <!-- 将资源属性配置文件放到classpath下  --><directory>src/main/resources</directory><targetPath>WEB-INF/classes</targetPath>                              <filtering>true</filtering> </resource></webResources></configuration>      </plugin>        </plugins></build>

其次,项目右键Run As --》 maven clean ---》maven build...  

最后就到了上面配置的

  <outputDirectory>F:/tomcat/apache-tomcat-7.0.70/webapps</outputDirectory>
在tomcat的wabapps目录下


原创粉丝点击