我按照http://openjdk.java.net/groups/build/的指令为windows构建了一个32位openjdk(jdk8u92),构建过程成功没有任何问题,但是当我使用swing运行程序时使用新建的openjdk,这很简单gui程序,发生以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: sun.font.SunFontManager
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:82)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.getFamily(Font.java:1220)
at java.awt.Font.getFamily_NoClientCode(Font.java:1194)
at java.awt.Font.getFamily(Font.java:1186)
at sun.swing.SwingUtilities2.displayPropertiesToCSS(SwingUtilities2.java:1478)
at javax.swing.plaf.basic.BasicHTML$BasicDocument.setFontAndColor(BasicHTML.java:366)
at javax.swing.plaf.basic.BasicHTML$BasicDocument.<init>(BasicHTML.java:355)
at javax.swing.plaf.basic.BasicHTML$BasicEditorKit.createDefaultDocument(BasicHTML.java:311)
at javax.swing.plaf.basic.BasicHTML.createHTMLView(BasicHTML.java:54)
at javax.swing.plaf.basic.BasicHTML.updateRenderer(BasicHTML.java:207)
at javax.swing.plaf.basic.BasicLabelUI.propertyChange(BasicLabelUI.java:417)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8428)
at javax.swing.JLabel.setText(JLabel.java:330)
......
我可以在openjdk中找到sun.font.SunFontManager
,但似乎类加载器无法加载该类......
任何人都可以提供帮助吗?
答案 0 :(得分:0)
最后,我自己找到了这个问题的根本原因:
此问题是由我将openjdk与由gnuwin32编译的freetype 2.3.5_1 lib链接引起的,但我的本地构建环境基于cygwin。所以, 当运行awt java代码时,freetype 2.3.5_1会抱怨找不到依赖项(应该是zip2.dll,gunwin32在构建freetype 2.3.5_1时添加它),而openjdk吃了这个错误并抛出sun.font.SunFontManager找不到
解决方案是使用visual studio在我自己的环境中构建freetype。