【发布时间】: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