【问题标题】:Maven src/main/resources not filteringMaven src/main/resources 没有过滤
【发布时间】:2013-08-04 15:58:53
【问题描述】:

当我执行 jetty:run 时...产生的战争过滤器正确。 当我打包时......由此产生的战争没有正确过滤。 我做错了什么?

  <build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.properties</exclude>
                <exclude>**/*.xml</exclude>
            </excludes>
        </resource>
    </resources>
    <finalName>MyWarName</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <source>${jdk.source}</source>
                <target>${jdk.target}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <configuration>
                <contextXml>${basedir}/src/main/webapp/WEB-INF/jetty-context.xml</contextXml>
            </configuration>

        </plugin>
    </plugins>
</build>

【问题讨论】:

  • 为什么你要包含然后排除相同的资源?
  • 我不是第一个块包含过滤的资源,第二个包含未过滤的资源。
  • 为了简化您可以删除第二个块,看看它是否有帮助。它在这里为你做什么?它读起来像:第一个块包含用于过滤的文件;第二个块正在排除不被过滤的文件
  • 如果你想从你的战争中排除文件,你可以使用 maven-war-plugin:maven.apache.org/plugins/maven-war-plugin/examples/…

标签: maven filtering war


【解决方案1】:

你需要添加没有被替换的属性:

系统属性

项目属性:

<project>
...
<properties>
    <the_name>value</value>
</properties>
...
</project>

使用 .properties 文件构建过滤器:

<project>
...
<build>
    <filters>
        <filter>the_values.properties</filter>
    </filters>
</build>
...
</project>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-25
    • 2014-09-19
    • 2017-04-11
    • 1970-01-01
    相关资源
    最近更新 更多