【问题标题】:Maven build to include file in root folder of jarMaven构建以在jar的根文件夹中包含文件
【发布时间】:2018-11-15 16:22:13
【问题描述】:

我正在为我的项目使用 Spring Boot 应用程序。在其中一个项目中,我需要在 jar 根路径中包含一个 config.properties 文件。 enter image description here 因为在我的项目中,一个外部 jar 期望来自文件系统的这个属性文件,意味着项目的根路径。

propertieFile.load(new FileInputStream("config.properties"));

实际上我在 eclipse maven 项目中有这个属性文件,但是在构建时它被忽略了。 enter image description here 你们中的任何一个都可以帮忙吗?提前致谢。

【问题讨论】:

  • 照常放入src/main/resources...

标签: maven maven-plugin spring-boot-maven-plugin maven-resources-plugin maven-jar-plugin


【解决方案1】:

使用 maven standard directory layout。如果您使用这些目录,则无需进一步配置,文件将添加到类路径中。

对于此类文件,建议使用 src/main/resources 文件夹。

使用这个你可以使用类加载器来输入你的文件。

try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(fullPath)) {
    propertieFile.load(is);
} 

【讨论】:

  • 这并没有解决问题。许多使用基于云的应用程序需要根级别的文件。
  • @TonyEdwards 是的,但主题是询问项目/jar 中的 config.properties:“我在 eclipse maven 项目中有这个属性文件”。
猜你喜欢
  • 1970-01-01
  • 2019-12-04
  • 2014-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-12
  • 2011-12-07
相关资源
最近更新 更多