1. Background
When you use Jasperreport to generate a report at work, the error font \ "Microsoft Jas black \" is not available to the JVM appears. See the Javadoc for more details.
2. Analysis
The development environment is WINDOW7, and the problem does not occur. The test environment is Linux and this error occurs. Based on the literal meaning of the error, the initial assumption is that the font is not on the Linux server.
3. Install fonts
- Install the Chinese fonts on the WINDOW7 to Linux
- Window7 the font location: C:\Windows\Fonts. As shown below:
- Copy the Simplified Chinese font to Linux and save the path as:/usr/share/fonts/chinese/truetype. As shown below, the visualizer is WINSCP:
- To install fonts using the command:
Cd/usr/share/fonts/chinese/truetype
Mkfontscale
Mkfontdir
Fc-cache–fv
Fc-list:lang-zh
Note the font selected in the figure Microsoft Jas Black, the left Chinese language, the right side is English expression
4. Re-analysis
If the problem has been solved after restarting the service, congratulations. But I am in fact, very clear Linux has installed the font, but still prompt error. This is probably caused by the environment is not the same problem, so I think of the remote debug debugging, Remote Debugging configuration: http://www.cnblogs.com/zhuqianchang/p/9044699.html
Error location in fontutil.java350 line, check the source code as follows:
According to the source code analysis, first obtain the system font to join the cache, the cache is a set set, and then determine whether the specified font is in the collection. So after debugging in, look at the font in the cache, found that there is no font "Microsoft ya Black", but found the font "Microsoft Yahei". So the problem is clear, although the font is installed, but the Linux system language is English, so the contains method does not match to the font "Microsoft Jas Black", so error.
5. Modify the system language
Echo $LANG
vi/etc/sysconfig/i18n
English: lang= "en_US. UTF-8 "
English: lang= "ZH_CN. UTF-8 "
source/etc/sysconfig/i18n
6. Restart the service
The system fonts are stored in the cache according to the source code, so the service needs to be restarted. After restarting, the problem is solved smoothly
Font \ "Microsoft Jas black \" is not available to the JVM. See the Javadoc for more details.