【问题标题】:Where to put properties file (in connection with maven assembly)将属性文件放在哪里(与 maven 程序集有关)
【发布时间】:2017-04-03 14:52:38
【问题描述】:

当我在 Eclipse 中启动我的应用程序时,在 src/main/resources 文件夹中有一个属性文件是没有问题的。然后当我运行maven install 时,这个属性文件在maven 程序集的帮助下被放入config 文件夹中。所以以下问题:

在 Eclipse 中工作时,我只需使用以下命令访问属性文件:

File propsFile = new File( "src/main/resources/settings.properties" );

在maven install 之后,我当然不能再访问这个文件了。但是哪个工作流程最好,在我的 Eclipse 开发期间和 maven install 之后访问文件而不用两次?!

maven install 之后我的装配结构如下所示:

application folder
    |----bin
        |----batch file to start my application
    |----lib
        |----my application jar
        |----other dependencies jars
    |----config
        |----settings.properties

提前非常感谢:)

【问题讨论】:

  • 您的应用程序组装完成后是如何启动的?通过马文?通过一个简单的系统脚本?
  • 是的,使用 .cmd 文件 ...

标签: java eclipse maven properties maven-assembly-plugin


【解决方案1】:

如果您通过脚本文件启动应用程序,我建议您将 settings.properties 所在的文件夹包含到类路径中:

    1234563类路径。
  • 并且在您的脚本文件中,您只需在执行类路径的开头预先添加<application>\config 文件。

但是你必须改变从程序中读取资源的方式:使用File API 替换为ClassLoader.getResourceAsStream:

InputStream input=getClass().getClassLoader().getResourceAsStream("settings.properties");
Properties properties=new Properties(input);

【讨论】:

    猜你喜欢
    • 2011-08-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 2023-04-09
    • 1970-01-01
    • 2010-10-02
    相关资源
    最近更新 更多