如何在IntelliJ中将资源文件添加到JAR
我正在使用IntelliJ IDEA 14,我想在src之外添加文件到JAR文件。 这是我目前的项目结构。
我想将layout.txt和saveddata.txt添加到JAR文件可执行文件中。 我一直在谷歌上搜索一段时间无法找到解决方案
如果你需要看我的代码。 这就是我读文件的方式
private Path layoutPath = Paths.get("resources/layout.txt"); content = new String(Files.readAllBytes(layoutPath));
这是我的项目结构
- 创建一个名为“resources”的文件夹,其级别与“src”相同
- 右键单击该文件夹,选择“将目录标记为 – >资源根”
- 在项目根目录下创建名为“resources”的新目录。
- 右键单击该目录并选择“Mark Directory As”==>“Resources Root”选项。
它仍然适合我。 我试过了:
+ "Mark Directory As" ==>"Resources Root" + getClassLoader().getResourceAsStream() + getClass().getClassLoader().getResource() and Thread.currentThread().getContextClassLoader().getResourceAsStream()
- Hibernate ConfigurationException:找不到cfg.xml资源 IntelliJ
- @Nullable / @NotNull与IntelliJ IDEA,Maven和JSR 305
- 在eclipse中关闭intellij想法中未使用的模块
- 如何从IntelliJ IDEA启动Vert.x服务器?
- ‘jvm-1.8’不是’-target’的有效选择
- IntelliJ null检查警告
- IntelliJ IDEA GUI构建器 – 未生成Java代码
- IntelliJ IDEA + Maven iml文件中依赖项的需要是什么?
- IntelliJ 2018.1首选项中的“使用’ – release’选项”是什么?