Maven pom引用了外部属性文件。如何在您的Java程序中读取它?

时间:2019-02-28 18:23:32

标签: java maven maven-plugin maven-surefire-plugin

我正在使用org.codehaus.mojo插件,它是read-project-properties目标。喜欢...

  <plugins>
    <!-- Reading properties file for login credentials BEGIN -->
  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0.0</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>

  <file>${basedir}/../datahubui_project_setup/config.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>
 <!-- END Reading properties file for login credentials -->

        <plugin>

它构建良好,没有错误。然后在我的Java方法中,我正在做

private void readCredentialsFromPropertyFile() {
    try {

        input = new FileInputStream("config.properties");

        // load a properties file
        prop.load(input);

    // get the property value and print it out
     System.out.println("@@@@@@@@@@@"+prop.getProperty("userId"));
    } catch (IOException ex) {
        ex.printStackTrace();
    } 
}

我得到java.io.FileNotFoundException: config.properties(没有这样的文件或目录)

我什至尝试将文件的其他路径设置为“ $ {basedir} /../ datahubui_project_setup / config.properties”,仍然没有用。

0 个答案:

没有答案