我已经尝试过类似的努力的一些答案,但没有什么我想要实现比较适合...行家:属性路径不会被替换(读第二其它属性文件)
这是我m试图做:
我想基于(其他)属性文件生成(过滤)属性文件。
我们有一个属性文件,其中包含一般属性。该文件(现在是default.properties)被读取并解析为一个魅力。
然后,我们也想根据环境具体的属性。 (我知道,不是好的做法,但是这是最好的解决方案,因为我们有自主建立在不同的机器上,并产生所有属性的无处不在方便)
这就是我们陷入困境......
当指定一个包含属性的路径(在这种情况下为targetEnvironment)时,它不会被填充其值。
- 我已经尝试切换阶段(生成资源/初始化/处理资源);与
- 使用CLI属性:
- 使用的配置文件调用:
<profiles>
<profile>
<id>nt</id>
<properties>
<targetEnvironment>NT</targetEnvironment>
</properties>
</profile>
</profiles>
这是(部分)当前POM(仅相关部分(聚甲醛内)显示):
<project>
(some maven code)
<build>
(other maven code)
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>execution1</id>
<phase>generate-resources</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/env_properties/env/${targetEnvironment}/specific.properties</file>
</files>
</configuration>
</execution>
<execution>
<id>execution2</id>
<phase>generate-resources</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>src/env_properties/env/default/default.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.soebes.maven.plugins</groupId>
<artifactId>maven-echo-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>echo</goal>
</goals>
</execution>
</executions>
<configuration>
<echos>
<echo>Animal: src/env_properties/env/${targetEnvironment}/specific.properties</echo>
<!-- prints: src/env_properties/env/NT/specific.properties -->
</echos>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/env_properties/base</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
奇怪的是,
,如果我用文字“NT”它的工作原理替换$ {} targetEnvironment,所以机制的工作,只有不更换...
我也试图更改插件版本,但某些版本甚至使它更糟...
任何想法?
感谢,
S.
编辑:另一个奇怪的事情,如果我不建了-DtargetEnvironment=NT
参数我得到一个构建失败的原因是:
[INFO]
[INFO] --- properties-maven-plugin:1.0.0:read-project-properties (execution1) @ batch3 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.644 s
[INFO] Finished at: 2017-04-21T15:55:11+02:00
[INFO] Final Memory: 41M/459M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:properties-maven-plugin:1.0.0:read-project-properties (execution1) on project batch3: Properties could not be loaded from File: C:\path\to\src\env_properties\env\${targetEnvironment}\specific.properties -> [Help 1]
[ERROR]