【问题标题】:maven variable property filteringmaven变量属性过滤
【发布时间】:2012-01-13 06:41:19
【问题描述】:

我正在尝试获取一些变量属性值并使用 Maven 配置文件来获得正确的输出。我已经为我的休眠 xml、log4j.properties 完成了这个并且没有问题。

所以它在项目#1 中对我有用,我在 /src/main/resources 下有一堆文件。我在maven中设置属性和资源过滤如下:

<properties>
    <log.level>DEBUG</log.level>
</properties>


<profiles>
    <profile>
        <id>production</id>
        <properties>
    <log.level>INFO</log.level>
        </properties>
    </profile>
</profiles>

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

以上操作没有问题。 但是,在我的 Project#2 中-我有一些具有可变属性的文件,但它们位于 /src/main/webapp/WEB-INF 下-我执行与上面相同的操作,除了指向 WEB-INF 的目录它不起作用。我在项目 #2 上尝试了将文件放在 /src/main/resources 下并且它有效。

所以在我看来,当文件位于 /src/main/webapp/WEB-INF 下时资源过滤有问题,但我需要该文件在那里,以便在生成战争时进入 WEB-INF 文件夹。

有没有人指点一下如何做到这一点?

以下是 pom.xml 中不起作用的片段(完全忽略了资源过滤)

<properties>
        <wsdl.url>http://stage/wsdl-url</wsdl.url>
</properties>

<profiles>
    <profile>
        <id>production</id>
        <properties>
    <wsdl.url>http://prod/wsdl-url</wsdl.url>
        </properties>
    </profile>
</profiles>

<build>
    <resources>
        <resource>
            <directory>src/main/webapp/WEB-INF</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

【问题讨论】:

    标签: maven maven-profiles


    【解决方案1】:

    我也有这个问题;我怀疑 POM 的主要 &lt;resources&gt; 部分被 war 插件忽略了,因此我想出了直接配置插件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
            <filters>
                <filter>filter.properties</filter>
            </filters>
            <webResources>
                <resource>
                    <directory>WebContent/WEB-INF</directory>
                    <filtering>true</filtering>
                    <targetPath>WEB-INF</targetPath>
                </resource>
            </webResources>
        </configuration>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 2015-06-10
      • 2013-06-07
      • 1970-01-01
      • 2016-03-24
      • 1970-01-01
      • 2015-10-18
      • 2013-01-23
      • 1970-01-01
      相关资源
      最近更新 更多