I'm attempting to build a .jar that contains a non-standard images and fonts, which I have added to the resource folder in my project. I am able to load them into 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 exported jar is run it is unable to load the font.
From the main menu, select File | Project Structure ( Ctrl+Alt+Shift+S ) and click Artifacts. and select an artifact format. On the page that opens in the right-hand part of the dialog, specify the artifact settings and contents.
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. ).
Build artifacts are files produced by a build. Typically, these include distribution packages, WAR files, reports, log files, and so on. When creating a build configuration, you specify the paths to the artifacts of your build on the Configuring General Settings page.
You can create your own artifacts in the project structure:
There you can add the directory contents of the resources folder. Press the green plus and navigate to your folder and add it. You can then click build-> build artifacts -> build. In my case the jar is created in ./out/artifacts folder.
Intellij is treating folders marked as "resources" as additional classpath directories which could be discovered by it's own autocomplete or in your case run/debug feature. Try right click on this folder and choose "Mark Directory As">"Unmark as Resources Root" to verify this assumption. If it's stopped working, you need to provide more reliable path taking into consideration where this file is located inside your resulting jar-file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With