Exporting font to jar in eclipse

五迷三道 提交于 2019-12-31 02:56:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!