我正在尝试清理Java Maven Web应用程序项目。在<build>
的{{1}}部分,我有以下内容:
pom.xml
在我的Mac上<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<filters>
<filter>profiles/${build.profile.id}.profile.properties</filter>
</filters>
[...other properties...]
</build>
,我/Users/anthony/workspace/my-project/
我的项目src/main/resources/profiles/
和local.profile.properties
。
然后,在我的pom中的maven个人资料中,我将qa.profile.properties
定义如下:
${build.profile.id}
当我在我的控制台并运行<profile>
<id>local</id>
[...stuff...]
<properties>
<build.profile.id>local</build.profile.id> <!-- or qa -->
[...stuff...]
</properties>
</properties>
时,我收到以下错误:
$ mvn clean install -Plocal
。
似乎Maven没有识别我的过滤配置文件属性文件的资源目录。这只适用于我明确放置属性文件的整个路径,如下所示:
Failed to execute goal ... on project my-project: Error loading property file '/Users/anthony/workspace/my-project/profiles/local.profile.properties'
我有没有办法明确说明<filters>
<filter>src/main/resources/profiles/${build.profile.id}.profile.properties</filter>
</filters>
?我认为我声明资源目录的重点是我可以使用它,尤其是用于声明过滤。
答案 0 :(得分:1)
资源目录只对正在构建的Java工件具有“资源”的含义,但对于Maven本身则没有。对于Maven,“resources”目录具有特殊含义,即Maven知道将这些文件复制到生成的jar文件中的位置。但是对于使用文件或过滤文件的Maven,你必须告诉Maven确切的路径,因为Maven不知道过滤的文件是资源,源文件还是其他东西。此外,您可以定义多个源或资源目录,并且Maven不知道,在哪个过滤器中。因此,您始终需要为Maven指定完整路径。
简而言之:
有没有办法让我不必明确说明src / main / resources?
没有