1

我有 Maven 项目。我需要编译这个项目进行测试和生产。

生产不应包含 private.key 文件。我像这样排除它:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <excludes>
            <exclude>license/private.key</exclude>
        </excludes>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>parking.application.Starter</mainClass>
                <classpathPrefix>lib/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
</plugin>

项目没有 Maven 配置文件。我应该为这个小例外创建配置文件还是有其他方法?如果我必须创建配置文件,我该如何在不重复太多代码的情况下做到这一点?

4

2 回答 2

1

我发现只有一种解决方案对配置文件使用无效属性,而对默认属性使用真实属性

<profiles>
    <profile>
        <id>privateKey</id>
        <properties>
            <exclude.private.key>none</exclude.private.key>
        </properties>
    </profile>
</profiles>
<properties>
    <exclude.private.key>license/private.key</exclude.private.key>
</properties>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <excludes>
                    <exclude>${exclude.private.key}</exclude>
                </excludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>parking.application.Starter</mainClass>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

运行生产:mvn
运行测试:mvn -P privateKey

于 2013-09-19T16:51:47.753 回答
0

您可以尝试使用该packagingExcludes参数。像这样的东西: -

<configuration>
    <packagingExcludes>META-INF/abc.xml</packagingExcludes>
</configuration>
于 2013-09-19T16:09:04.767 回答