pom.xml配置,针对mvn clean install -P参数(环境参数)打包

比如你有2个环境,一个dev,一个prod,

然后你在mvn打包的时候,可以通过-P来打包,是打dev包,还是prod包。

pom.xml可以这样配置

<profiles>
        <profile>
            <id>dev</id>
            <properties>
                <env>dev</env>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>  //如果不带-P但是,默认是dev
            </activation>
        </profile>
        <profile>
            <id>devtest</id>
            <properties>
                <env>devtest</env>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <env>prod</env>
            </properties>
        </profile>
    </profiles>

  

-Pdev / -Pprod 的参数dev/prod,会根据传入的参数代入到具体的打包配置中

 <build>
        <finalName>xzair-rest</finalName>
        <scriptSourceDirectory>src/main/java</scriptSourceDirectory>
        <resources>
            <resource>
                <directory>src/main/resources/${env}</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes>
                    <exclude>dev/*</exclude>
                    <exclude>devtest/*</exclude>
                    <exclude>prod/*</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <webResources>
                        <resource>
                            <directory>src/main/resources/${env}</directory>
                            <targetPath>WEB-INF/classes</targetPath>
                            <filtering>true</filtering>
                        </resource>
                        <resource>
                            <directory>src/main/resources</directory>
                            <filtering>true</filtering>
                            <excludes>
                                <exclude>dev/*</exclude>
                                <exclude>devtest/*</exclude>
                                <exclude>prod/*</exclude>
                            </excludes>
                        </resource>
                        <resource>
                            <directory>${project.basedir}/src/main/resources/lib</directory>
                            <targetPath>WEB-INF/lib</targetPath>
                            <filtering>false</filtering>
                            <includes>
                                <include>**/*.jar</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <!-- 过滤后缀为pem、pfx的证书文件 -->
                    <nonFilteredFileExtensions>
                        <nonFilteredFileExtension>pem</nonFilteredFileExtension>
                        <nonFilteredFileExtension>pfx</nonFilteredFileExtension>
                        <nonFilteredFileExtension>p12</nonFilteredFileExtension>
                    </nonFilteredFileExtensions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <path>/xzair-rest</path>
                    <charset>${project.build.sourceEncoding}</charset>
                    <port>${server.port}</port>
                    <uriEncoding>${project.build.sourceEncoding}</uriEncoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

  

cmd打包的时候可以这样打

mvn clean isntall -Pprod
或者
mvn clean install -Pdev

  

原文地址:https://www.cnblogs.com/achengmu/p/10647662.html

时间: 2024-10-12 23:53:30

pom.xml配置,针对mvn clean install -P参数(环境参数)打包的相关文章

pom.xml配置详解

转载自:http://www.cnblogs.com/zz0412/p/Maven_pom.html POM的全称是“ProjectObjectModel(项目对象模型)”. 1.声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://

【转】Maven pom.xml 配置详解

原文链接:https://yq.aliyun.com/articles/38271 pom.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 pom.xml配置详解

POM的全称是“ProjectObjectModel(项目对象模型)”. pom.xml详解 声明规范 <projectxmlns="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.0http://maven.apach

Maven笔记 pom.xml配置详解

pom.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/xsd/maven-4.0.0.xsd&quo

shell 脚本执行mvn clean install 报错 --MissingProjectException

ll 脚本执行mvn clean install 报错 12月12日北京OSC源创会 —— 开源技术的年终盛典 »   [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] --------------------------------------------------

【maven】mvn clean install出现 tools.jar not found

问题描述: 当我们在用eclipse和m2eclipse时 ,JAVA_HOME,CLASSPATH和MAVEN_HOME都配置好了,运行mvc clean install出现找不到  tools.jar. 问题分析: 是找不到tools.jar,而tools.jar一般是在C:\Program Files\Java\jdk1.7.0_15\lib之下的. 问题解决: Eclipse默认是运行在jre上的,而m2eclipse的一些功能要求使用JDK,如果不进行配置的话.问题的关键就是在配置ec

Maven-SSM项目pom.xml配置以及springmvc配置以及mybatis配置

一.Maven本地仓库的pom.xml配置 (全部是mysql数据库) 1 <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/xsd/ma

maven中打包项目为war包的pom.xml配置

maven中打包成war包的pom.xml配置(1)完整配置:这个是使用servlet的完整配置,其他的类似. <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

maven setting.xml和pom.xml配置详解

setting.xml配置 <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.o