【问题标题】:reading properties file into maven pom.xml not working将属性文件读入 maven pom.xml 不起作用
【发布时间】:2017-03-30 10:11:52
【问题描述】:

我需要在 maven pom.xml 中使用属性文件中的值,所以我使用 properties-maven-plugin 来读取我的属性文件,如下所示

pom.xml

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>read-project-properties</goal>
            </goals>
            <configuration>
                <files>
                    <file>${basedir}/src/main/resources/qura.properties</file>
                </files>
            </configuration>
        </execution>
    </executions>
</plugin>

qura.properties 文件包含类似这样的内容..

config.file.path = resources/python/config/test.py

我需要在 pom.xml 的资源元素中使用这个 config.file.path 变量

pom.xml

<resources>
    <resource>
        <directory>${basedir}/multilang/</directory>
        <includes>              
            <include>${config.file.path}</include>
        </includes>
    </resource>
<resources>

但是 ${config.file.path} 的值没有从 qura.properties 文件中占用,我在 jar 中找不到 test.py 文件。

我在这段代码中做错了什么?

提前致谢

【问题讨论】:

    标签: maven pom.xml properties-file


    【解决方案1】:

    尝试使用 1.0.0 版本并删除属性文件中等号周围的空格。

    例如:

    key=value
    

    【讨论】:

      【解决方案2】:

      IMO,无论您是否在属性文件中的等号周围放置空格都没有关系。您可能需要检查${config.file.path}是否存在于${basedir}/multilang指定的目录中

      下面的 sn-p 对我有用。

          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-resources-plugin</artifactId>
                  <version>2.6</version>
                  <executions>
                      <execution>
                          <id>copy-resources</id>
                          <goals>
                              <goal>copy-resources</goal>
                          </goals>
                          <configuration>
                              <resources>
                                  <resource>
                                      <directory>src/main</directory>
                                      <includes>
                                          <include>${config.file.path}</include>
                                      </includes>
                                  </resource>
                              </resources>
                          </configuration>
                          <inherited></inherited>
                      </execution>
                  </executions>
              </plugin>
      
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>properties-maven-plugin</artifactId>
                  <version>1.0-alpha-2</version>
                  <executions>
                      <execution>
                          <phase>validate</phase>
                          <goals>
                              <goal>read-project-properties</goal>
                          </goals>
                          <configuration>
                              <files>
                                  <file>${basedir}/src/main/resources/qura.properties</file>
                              </files>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
      

      【讨论】:

      • 谢谢 .. 但添加 maven-resources-plugin 以包含资源并删除属性文件中的空格对我不起作用。我确定 ${config.file.path} 目录存在。
      • 我的一般要求是我需要包含特定于特定于客户端的资源。例如,我想为 client-1 包含 test1.py,为 client-2 包含 test2.py,就像这样。 . 所以我尝试在属性文件中使用这个文件名并尝试在 pom.xml 中使用它.. 但它对我不起作用.. 有没有其他方法可以包含我需要的资源
      猜你喜欢
      • 2012-10-23
      • 2012-03-09
      • 2013-06-20
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多