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

经过多次尝试,终于可以在打包时在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>
时间: 2024-08-12 11:32:05

【Maven】构建war包时排除web.xml的相关文章

一般maven(war)工程的web.xml文件

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee htt

maven生成war包的两种方式

war包即对WEB应用程序进行打包,用于应用容器的部署.如在jboss中只要把war包丢入deploy目录下即可发布自己的应用了.打包方式有很多中,很多工具本身就支持此功能.下面主要介绍通过maven来操作的两种方式: 方法一: 即第一反应的那种啦,就是利用maven的maven-war-plugin. <build> <plugins> ...... <plugin> <groupId>org.apache.maven.plugins</groupI

(转)用 Maven 部署 war 包到远程 Tomcat 服务器

转自蒋国纲 www.cnblogs.com/guogangj/p/5505228.html 用Maven部署war包到远程Tomcat服务器 过去我们发布一个Java Web程序通常的做法就是把它打成一个war包,然后用SSH这样的工具把它上传到服务器,并放到相应的目录里,让Tomcat自动去解包,完成部署. 很显然,这样做不够方便,且我们在用SSH把文件拽上去的时候很可能会搞错.(当然了大厂就不会有这样的问题,因为人家有运维团队专门来干这个事情,哈哈) 现在我要的是:一行命令部署到本地服务器,

Maven开发基础总结(Maven自启动,Maven打war包,Maven热部署)

学习内容: 1.不依赖外部Tomcat,自己启动方式部署 2.Maven打war包,远程部署到centOS 3.Maven热部署(不关闭Tomcat部署应用) 做maven开发前提: 1.编码UTF-8 2.设置maven仓库位置(setting.xml文件里面配置Maven仓库的路径) 例如:<localRepository>G:\Maven\repository</localRepository>(这个仓库是公司Maven服务器仓库down下来的) 3.在eclipse中设置M

告诉maven,我真的不需要web.xml

<!-- 告诉maven,我真的不需要web.xml --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false<

配置ssm 时, web.xml 文件无 # 自动代码提示

环境:STS 版本:spring-tool-suite-3.8.1.RELEASE-e4.6-win32-x86_64 配置ssm 时, web.xml 文件无 如下图蓝色圈范围内的提示 问题与 链接 类似 后来在 链接 中 13楼 找到答案 解决方法如下: 在web.xml中先输入左尖括号(<),等提示框出来后,再删除这个符号,再在提示信息中翻到最下边儿就看到了. 原文地址:https://www.cnblogs.com/mumu122GIS/p/10012245.html

使用Maven构建javaWeb项目时,启动tomcat出错:严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.conte

在初学使用maven构建javaWeb的项目的时候,启动tomcat加载时,总是提示如下错误,辛苦一番终于找到解决办法. 严重: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderList

maven打war包注意之xml、properties文件没打进去解决方法

maven项目在ide中编译出的war包一般不会有很多问题. 但是经过集成环境打war包会出现war包中打不进xml.properties等文件.这样打war包不会报错,但是war包放进tomcat中部署就报错了. 解决方法是将src/main/java和src/main/resources中的配置文件在pom的build节点配置进去 之前在项目的集成中有遇到这种情况,记录下来. 例如:src/main/java中有个包放hibernate的映射xml,和sqlmap配置文件.        

创建Maven web项目时 出现 web.xml is missing and &lt;failOnMissingWebXml&gt; is set to true错误 pox.xml编译错误

今天创建一个maven项目 pom.xml出现如下错误: web.xml is missing and <failOnMissingWebXml> is set to true 这是因为你因为你WEB-INF下没有web.xml导致造成的 解决方案: 右击项目——>Java EE Tools——>Generate Deployment Descriptor Stub.然后系统会在src/main/webapp/WEB_INF文件加下创建web.xml文件.错误解决! 当然这个方法是