Unable to include folder in JAR
I am having trouble including a folder that is supposed to go with my program when I build an Artifact. The folder contains three subfolders, which all contain several .txt files. When I run it through Intellij, it works just as it's intended to. However, when I build the Artifact, I get a message saying the directory does not exist (fortunately, this is how it is meant to respond, but not when I know the directory does in fact exist :')). I have tried to structure the files in different ways, including having a directory called “Resources” be marked as a Resources Root that contains the main folder, but this does not work either. I am unsure if it's because I need to change my code or if it is not properly including the folders. This is my first time actually building a program to distribute to others, so I'm unfamiliar with the proper way to include files and write the code to match a built program. I have tried to research the right way, but I'm getting nowhere.
I began with the standard new File(), but have since learned it needs to be structured differently when it is an Artifact. I changed it to new File(getClass().getResource()), but this has not worked either. Any help would be very much appreciated. Thanks in advance!
Here is the Git repository with all of the files: https://github.com/Cking8864/MaterialsCostAnalysisTool
Please sign in to leave a comment.
Hello!
Depending on your intended usage scenario you can either mark
MaterialsListsdirectory as Resources Directory, then IDEA will automatically add its' contents to the root of the JAR or addMaterialsListsdirectory (or its' subdirectories) explicitly ("Directory Content" option under “Output Layout”) to the Artefact.For more information refer to our documentation.
In regards to using the resources files once the Artifact has been build, try the following code: