通过maven管理项目的生产、开发和测试环境的配置文件

本文介绍了如何使用Maven配置不同环境(开发、测试、线上)的资源路径,并通过示例展示了具体的POM.xml配置方法及命令行操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


POM.xml文件配置如下:

<build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resource/${package.environment}</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webappDirectory>${basedir}/src/main/webapp</webappDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <url>http://localhost:8080/manager/html</url>
                    <server>tomcat</server>
                    <path>/ewalletPayTest</path>
                </configuration>
                <version>1.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.8.1</version>
                <configuration>
                    <aggregate>true</aggregate>
                    <charset>UTF-8</charset>
                    <encoding>UTF-8</encoding>
                    <docencoding>UTF-8</docencoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <package.environment>dev</package.environment>
            </properties>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <package.environment>test</package.environment>
            </properties>
        </profile>
        <profile>
            <id>online</id>
            <properties>
                <package.environment>online</package.environment>
            </properties>
        </profile>
    </profiles>


maven命令执行如下:

mvn package -Ptest -Dmaven.test.skip=true

mvn package -Pdev -Dmaven.test.skip=true

mvn package -Ponline -Dmaven.test.skip=true


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值