Search code examples
javaswinggraphics2d

Custom Font's In Java, Works in Eclipse but not .Jar [Using ResourceStream]


So I am in a bit of a rut in terms of using a Custom Font I picked up, before going deeper I wanted to see if I was able to export my Program from Eclipse and to a Jar with it still being able to run. This trial was unsuccessful even though I underwent the procedures necessary to make it so.

PLEASE NOTE that the program runs properly in a Jar if the custom font attempt is taken out.

Here is the sample code I am working with

GraphicsEnvironment ge  = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font menu = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Fonts/Menu/gamecuben.ttf"));
        ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/Fonts/Menu/gamecuben.ttf")));
        g.setFont(menu.deriveFont(18f));

This is the strung out example, before I had it a lot shorter but trying to pinpoint the issue has been my main concern.

What Happens? In Eclipse it loads properly into my project, everything is fine but when exported into the Jar, it doesn't actually boot to the screen with the Custom Font.

Boot Order

Eclipse: Boot Screen --> Menu

JAR: Boot Screen --> Stalls (Stays at boot screen)

I have tried to see if any errors were ocurring to where I could trace it but when I tried to use PrintWriter to print a text file to my Desktop with the possible error loading the Custom Font, nothing happened.

Any ideas would be awesome at this point, I will keep this updated with new information if any errors do arise.

Thank you.


Solution

  • Found out the issue for anyone addressing this, for some reason the audio player in my game quit working in the JAR file (Might have tweaked something). Anyways this function should work.

    Sorry for the inconvenience