在我当前的项目中,我有一个子模块,它使用 maven exec 插件来运行测试服务,该服务从 resources/testResources 文件夹之外的位置提取配置文件。
我需要使用过滤将环境变量注入(inject)到一些配置文件中。这适用于其中一个文件,一个 .properties 文件,但不适用于另一个 .json 文件。在后一种情况下,它只是将变量留在 json 文件中。这两个文件在过滤后的目录中紧挨着。
这是来自子模块的过滤片段:
<build>
<finalName>${artifactId}</finalName>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>../etc</directory>
</testResource>
</testResources>
json文件:
{ "customMappings" :
{ "tag:example.com:/vagrant/" : "file:${VAGRANT_CWD}" }
}
简化的项目结构:
- 项目
- 等
- 配置属性
- 配置.json
- 子模块
- pom.xml
- 等
子模块肯定会加载这两个文件,但只会过滤 .properties 文件。
它是一个 json 文件,是否有什么特别之处可以防止对其进行过滤?有什么可以做的吗?
最佳答案
就其值(value)而言,我最终确实让它发挥了作用。我发现我必须直接列出要包含的文件才能对其进行处理(这已经很长时间了,希望这是正确的解决方案):
<build>
<finalName>${artifactId}</finalName>
<testResources>
<testResource>
<filtering>true</filtering>
<directory>../etc</directory>
<includes>
<include>config.json</include>
<include>config.properties</include>
</includes>
</testResource>
</testResources>
...
关于java - json文件的maven资源过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38750784/