如何在IntelliJ中将资源文件添加到JAR [英] How to add resource file to JAR in IntelliJ

查看:161
本文介绍了如何在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));

这是我的项目结构



< IMG SRC = https://i.imgur.com/HFqaZwz.jpg ALT = 布局结构>

解决方案

  1. 在与src相同的级别创建一个名为resources的文件夹。

  2. 右键单击该文件夹,选择将目录标记为 - >资源根


I am using IntelliJ IDEA 14 and I want to add file outside of src to the JAR file. This is my current project structure.

I want to add layout.txt and saveddata.txt to the JAR file executable. I've been googling on that for a while can't find the solution

In case you need to see my code. This is how I am reading file

private Path layoutPath = Paths.get("resources/layout.txt");
content = new String(Files.readAllBytes(layoutPath));

Here is my project structure

解决方案

  1. Create a folder called "resources" at the same level as "src"
  2. Right click the folder, select "Mark Directory As -> Resources Root"

这篇关于如何在IntelliJ中将资源文件添加到JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆