Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

Layout Structure

like image 734
Vincent Paing Avatar asked Apr 27 '15 05:04

Vincent Paing


People also ask

How do I add resources to a Java project IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Project Settings | Modules. Select the necessary module and then open the Sources tab in the right-hand part of the dialog. Click Add Content Root and specify the folder that you want to add as a new content root.

How do I add files to IntelliJ resources?

To do this, open the File > Project Structure dialog, select the Modules tab, and click on the resources folder. The result will be as shown below. Your application can now access resources from the resources folder.

How manually add jar in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules | Dependencies. Alt+Insert and select a dependency type: JARs or directories: select a Java archive or a directory from files on your computer.


1 Answers

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

enter image description here

like image 109
Brian Topping Avatar answered Oct 03 '22 02:10

Brian Topping