세모 :
나는 springboot 지방 항아리에 포함 된 글꼴을 사용하고자 할 때 나는 이상한 행동을 발견했다. 로부터 글꼴을로드 내 로컬 컴퓨터에 테스트를 실행하면 /resources
디렉토리, 그것은 완벽하게 작동합니다. 내가 받는다는와 응용 프로그램을 구축하고 터미널에서 실행한다면, 그때받을 것이다 :
java.io.IOException: Problem reading font data.
at java.awt.Font.createFont0(Font.java:1000)
at java.awt.Font.createFont(Font.java:877)
나는 해결책을 찾기 위해 노력하고 다음을했다 :
- (손상된 테이블이나 STH에 대한 또 다른 오류가 가끔.) 다른 글꼴을 사용하여
- 테스트 동작에 고정 표시기의 오픈 JDK 용기의 내장 된 다양한 버전
- 우분투 컨테이너 설치 오픈 JDK를 구축
- 데비안 이미지, 설치 FC-캐시를 사용을 통해 폰트 제공
/usr/share/fonts/truetype/europlate
fc-cache -f -v
- 임시 파일을 생성, 단지 접근의 문제가 단지 내에서이없는 것을 확인합니다.
- 너무 글꼴을로드에 실패 내 터미널에서 응용 프로그램을 실행
- 글꼴을 사용하는 편집자에 작동하고 경우에도 응용 프로그램 실행 IDE에서 (NO 테스트)
방법:
public Font getFont() throws IOException, FontFormatException {
File f = File.createTempFile("dang", "tmp");
assert f != null;
f.delete();
ClassLoader classLoader = getClass().getClassLoader();
Font font = Font.createFont(Font.TRUETYPE_FONT, classLoader.getSystemResourceAsStream("EuroPlate.ttf"));
font.deriveFont(105f);
System.out.println(font.getFontName());
return font;
}
편집 : -> 작품 IDE는 응용 프로그램을 실행
터미널 실행 응용 프로그램 -> 실패
스택 트레이스 :
java.io.IOException: Problem reading font data.
at java.desktop/java.awt.Font.createFont0(Font.java:1183)
at java.desktop/java.awt.Font.createFont(Font.java:1052)
at components.NumberPlateUtility.getFont(NumberPlateUtility.java:81)
at components.NumberPlateUtility.completeImage(NumberPlateUtility.java:173)
at main.NumberplateClientCommands.one(NumberplateClientCommands.java:63)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:223)
at org.springframework.shell.Shell.evaluate(Shell.java:169)
at org.springframework.shell.Shell.run(Shell.java:134)
at org.springframework.shell.jline.InteractiveShellApplicationRunner.run(InteractiveShellApplicationRunner.java:84)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:783)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:773)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
at main.Main.main(Main.java:20)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Malathi :
이 코드는 작동합니다 :
public Font getFont() throws IOException, FontFormatException {
File f = File.createTempFile("dang", "tmp");
assert f != null;
f.delete();
ClassLoader classLoader = getClass().getClassLoader();
Font font = Font.createFont(Font.TRUETYPE_FONT, classLoader.getResourceAsStream("EuroPlate.ttf"));
font.deriveFont(105f);
System.out.println(font.getFontName());
return font;
}
의 변화를 참고 classLoader.getResourceAsStream
. 이 확인 대답을 더 설명.