[英]How to add resource file to JAR in IntelliJ
I am using IntelliJ IDEA 14 and I want to add file outside of src to the JAR file.我正在使用 IntelliJ IDEA 14,我想将 src 之外的文件添加到 JAR 文件中。 This is my current project structure.
这是我目前的项目结构。
I want to add layout.txt and saveddata.txt to the JAR file executable.我想将 layout.txt 和 saveddata.txt 添加到 JAR 文件可执行文件中。 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这是我的项目结构
It's still for me.它仍然是给我的。 I tried:
我试过:
+ "Mark Directory As" ==>"Resources Root"
+ getClassLoader().getResourceAsStream()
+ getClass().getClassLoader().getResource()
and Thread.currentThread().getContextClassLoader().getResourceAsStream()
For me, the resources
directory was already marked as Resources Root
but the content was missing in the jar
.对我来说,
resources
目录已经被标记为Resources Root
但内容在jar
中丢失。 I had to manually add the resources
dir to the jar
artifact using the Project Structure
window.我必须使用“
Project Structure
窗口手动将resources
目录添加到jar
工件。
Project Structures
windowProject Structures
窗口Artifacts
and click on the +
button and then select Directory Content
Artifacts
并单击+
按钮,然后选择Directory Content
resources
directoryresources
目录Apply
then OK
Apply
然后OK
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.