问题
I'm trying to export a font so that you don't have to install the font to run the game it's working in eclipse but exporting it doesn't work
the folder structure is as following:
Project_name
/src
-Core(package)
-game(package)
/Fonts
-Origin-Light.ttf
I load the font in with following command:
font = Font.createFont(Font.TRUETYPE_FONT,
new FileInputStream("./Fonts/Origin-Light.ttf"));
in eclipse it's working just fine, but exporting doesn't seem to load in the font
edit: Structure in jar file:
/core
- main.class
- ....
/Fonts
- Origin-Light.ttf
/game
- otherclasses.class
/META-INF
- MANIFEST.MF
/org
/eclipse
some more folders
回答1:
Put the fonts folder inside of your source folder, I believe that's the issue:
Project_name
/src
/Fonts
-Origin-Light.ttf
-Core(package)
-game(package)
Resolved in chat, final code:
try {
font = Font.createFont(Font.TRUETYPE_FONT,
trial.class.getClassLoader().getResourceAsStream("Fonts/Origin-Light.ttf"));
} catch (Exception e) {
e.printStackTrace();
}
来源:https://stackoverflow.com/questions/12131584/exporting-font-to-jar-in-eclipse