Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java maven:未在路径中替换属性(读取其他第二个属性文件)_Java_Maven_Properties - Fatal编程技术网

Java maven:未在路径中替换属性(读取其他第二个属性文件)

Java maven:未在路径中替换属性(读取其他第二个属性文件),java,maven,properties,Java,Maven,Properties,我已经尝试过一些类似尝试的答案,但没有什么与我想要达到的目标完全相符 这就是我想做的: 我正在尝试基于(其他)属性文件构建(筛选)属性文件 我们有一个包含常规属性的属性文件。该文件(目前为default.properties)像一个符咒一样被读取和解析 然后,我们还希望根据环境拥有特定的属性。 (我知道,这不是一个好的做法,但这是最好的解决方案,因为我们在不同的机器上有独立的构建,并且在任何地方生成所有属性都不方便) 这就是我们遇到麻烦的地方 指定包含属性(本例中为targetEnvironme

我已经尝试过一些类似尝试的答案,但没有什么与我想要达到的目标完全相符

这就是我想做的:

我正在尝试基于(其他)属性文件构建(筛选)属性文件

我们有一个包含常规属性的属性文件。该文件(目前为default.properties)像一个符咒一样被读取和解析

然后,我们还希望根据环境拥有特定的属性。 (我知道,这不是一个好的做法,但这是最好的解决方案,因为我们在不同的机器上有独立的构建,并且在任何地方生成所有属性都不方便)

这就是我们遇到麻烦的地方

指定包含属性(本例中为targetEnvironment)的路径时,不会用其值填充该路径

  • 我已经尝试过切换阶段(生成资源/初始化/处理资源)
  • 将cli属性与以下内容一起使用:
    mvn clean install-DtargetEnvironment=NT
  • 使用名为的配置文件:
(在pom内)


我不知道如何解决最初的问题,但我找到了一些我想做的事情:

如果您有一个属性文件(使用值替换其他属性文件中的值;例如:)

(顶级.properties)

以及一个特定的属性文件(基于在构建时通过调用例如
mvn clean install-DtargetEnvironment=NT
提供的属性)

(src\env\u properties\env\NT\specific.properties)

然后第一个属性可以如下读取:

    <build>

        (some maven code)

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <id>execution1</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/env_properties/env/default/top_level.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        (other maven code)

    </build>
    <build>

        (some maven code)

        <filters>
            <filter>src/env_properties/env/${targetEnvironment}/specific.properties</filter>
        </filters>

        (other maven code)

    </build>
(之后)

[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]
ejb.server.url=not yet defined
ejb.server.user=not yet defined
ejb.server.pwd=not yet defined
garrafra.doesntbestaat=anotherTest
    <build>

        (some maven code)

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>properties-maven-plugin</artifactId>
            <version>1.0.0</version>
            <executions>
                <execution>
                    <id>execution1</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                        <files>
                            <file>src/env_properties/env/default/top_level.properties</file>
                        </files>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        (other maven code)

    </build>
    <build>

        (some maven code)

        <filters>
            <filter>src/env_properties/env/${targetEnvironment}/specific.properties</filter>
        </filters>

        (other maven code)

    </build>
java.naming.provider.url=${ejb.server.url}
java.naming.security.principal=${ejb.server.user}
java.naming.security.credentials=${ejb.server.pwd}

blie=${garrafra.doesntbestaat}
java.naming.provider.url=not yet defined
java.naming.security.principal=not yet defined
java.naming.security.credentials=not yet defined

blie=anotherTest