【问题标题】:IntelliJ Java 11 resources from submodules are not accessible来自子模块的 IntelliJ Java 11 资源不可访问
【发布时间】:2019-03-08 13:54:19
【问题描述】:

我在 IntelliJ 中构建应用程序时遇到问题。

如果我有 2 个模块:

应用程序; 应用程序.gui

在 ressources 文件夹下的应用程序 gui 中,我有一个图像 /layout/image/background.jpg

在这个模块中,我收到了这张图片,因为它不存在。这只是 IntelliJ 打包问题,因为在 Maven 中构建的相同项目可以正常工作。

我应该如何配置我的 IntelliJ 以使其正常工作?

https://gitlab.com/mszymkowiak/simgentree/tree/simgentree-start/simgentree.project

不相关How to access a resource file in src/main/resources/ folder in Spring Boot

因为这些文件可能不是由 IntelliJ 构建的。我已经尝试过这个解决方案,它为我的子模块返回始终为空。 我在 intelliJ 的 Java11 中的 JavaFX 应用程序中遇到了同样的问题 (java8 中的相同应用程序工作正常,但是从 IntelliJ 运行它时,子模块中的任何资源都不可见)

   System.out.println("Empty path exist ? : "+ resourceLoader.getResource("").exists());
   System.out.println("mainbackground path exits ? :  " +resourceLoader.getResource("layout/images/mainbackground.jpg").exists());

给:

Empty path exist ? : false
mainbackground path exits ? :  false

@编辑 我添加到名为 : static 的资源文件夹并将文件移到那里,它似乎有效。但我想知道,为什么没有静态时它不起作用

【问题讨论】:

  • 不,这不是我以前见过的......而且它不起作用。正如我在 Maven 作品中解释的那样。这是 IntelliJ 问题
  • 检查嵌入式 maven 版本更新为本地 maven 路径。 idea-settings - Build- execution -> Deployment -> Build Tolls -> Maven -> Maven Home directory

标签: intellij-idea java-11


【解决方案1】:

Java 11 与 IDEA 嵌入式 maven 版本不兼容。用你当地的 maven 更新它重试

【讨论】:

  • 我使用 maven 3.6。正如我提到的,由 maven 编译的 jar 是可以的。仅来自 IntelliJ。只有在资源中我没有静态文件夹。如果我将所有文件夹都移到静态,它可以工作
  • Spring boot 自动配置默认扫描静态资源。好像是这个原因。您需要阅读为 claspath。
猜你喜欢
  • 1970-01-01
  • 2018-06-27
  • 1970-01-01
  • 2011-01-28
  • 2017-12-28
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-09-26
相关资源
最近更新 更多