码迷,mamicode.com
首页 > Web开发 > 详细

【Maven】构建war包时排除web.xml

时间:2017-07-28 13:32:13      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:tomcat7   路径   pack   pre   目的   over   instance   led   没有   

经过多次尝试,终于可以在打包时在maven-war-plugin中配置来忽略掉web.xml

 

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xank</groupId>
    <artifactId>zheng</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <name>security Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <finalName>zheng</finalName>
    </properties>

    <repositories>
        <repository>
            <id>nexus</id>
            <name>MZONE</name>
            <url>http://www.xank.com.cn/nexus/content/groups/public/</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <!-- 设置war包名称 -->
        <finalName>/${finalName}</finalName>
        <resources>
            <!-- 包含hbm.xml(或者将xhm.xml放到resource中) -->
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.hbm.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                    <include>**/*.txt</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <!-- web 目录 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <configuration>
                    <webResources>
                        <resource>
                            <excludes>
                                <exclude>**/WEB-INF/web.xml</exclude>
                            </excludes>
                            <directory>src/webapp</directory>
                        </resource>
                    </webResources>
                    <!-- 下面两个配置没有生效,这里贴出是表示提醒 
                    <packagingExcludes>src/webapp/WEB-INF/web.xml</packagingExcludes>
                    <warSourceExcludes>src/webapp/WEB-INF/web.xml</warSourceExcludes>
                    -->
                </configuration>
            </plugin>
            <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>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/${project.artifactId}</path>
                    <url>http://127.0.0.1:8081/manager/text</url>
                    <server>tomcat7</server>
                    <username>admin</username>
                    <password>admin</password>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <!-- 快速部署 (结合部署脚本使用) -->
            <id>deploy</id>
            <properties>
                <finalName>security</finalName>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.8</version>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <configuration>
                                    <target>
                                        <copy todir="${basedir}/target/classes/" overwrite="true">
                                            <fileset dir="${basedir}/release/deploy/resources/" />
                                        </copy>
                                        <!-- 目的路径不能写成 ${basedir}src/webapp/WEB-INF/ 会造成文件修改 -->
                                        <copy todir="${basedir}/target/${project.artifactId}/WEB-INF/" overwrite="true">
                                            <fileset dir="${basedir}/release/deploy/WEB-INF/" /> </copy>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

 

【Maven】构建war包时排除web.xml

标签:tomcat7   路径   pack   pre   目的   over   instance   led   没有   

原文地址:http://www.cnblogs.com/cpuz/p/7249656.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!