Intellij resources not embedded artifact

I am trying to create a .jar that contains non-standard images and fonts that I added to the resource folder in my project. I can upload them to my project with the following code.

URL url = ClassLoader.getSystemResource("./some_font.ttf"); Font font = Font.createFont(Font.TRUETYPE_FONT, url.openStream()); 

While this works, when I run the program in the IDE, when the jar is exported, it cannot load the font.

+7
java intellij-idea gradle
source share
2 answers

You can create your artifacts in the project structure: enter image description here

There you can add the contents of the directory to the resource folder. Click the green plus and go to your folder and add it. Then you can click build-> build artifacts -> build. In my case, the jar is created in the folder. / Out / artifacts.

+7
source share

Intellij treats folders marked as "resources" as additional class directories that can be detected using native autofill or in your startup / debugging function. Try right-clicking on this folder and selecting Mark Directory As> Unmark Resources to check this assumption. If it stops working, you need to provide a more reliable path, taking into account where this file is located inside the resulting jar file.

+1
source share

All Articles