【问题标题】:Loading a Properties File From an External Jar从外部 Jar 加载属性文件
【发布时间】:2014-12-30 22:33:45
【问题描述】:

我有一个属性文件,它存在于一些外部 jar 中。 给定外部 jar 的路径,如何在 java 中加载此属性文件? (我知道 prperties 文件在 jar 中的位置)

例如,jar 文件:/home/jars/abc.jar 在这个 jar 里面我有 prop/abc.properties。

请注意,jar 不存在于类路径中(所以我不能使用 getResourcesAsStream),而是在运行时获取 jar 的路径。

【问题讨论】:

    标签: java jar properties-file


    【解决方案1】:
    JarFile jarFile = new JarFile("path/to/jarFile.jar");
    InputStream inputStream = jarFile.getInputStream(jarFile.getEntry("path/inside/the/jar/to/propFile.properties"));
    Properties properties = new Properties();
    properties.load(inputStream);
    

    【讨论】:

      猜你喜欢
      • 2014-12-16
      • 2012-12-06
      • 1970-01-01
      • 2015-08-27
      • 1970-01-01
      • 2014-11-17
      • 2016-06-18
      • 1970-01-01
      • 2015-07-01
      相关资源
      最近更新 更多