当前位置: 动力学知识库 > 问答 > 编程问答 >

java - NoClassDefFoundError when running awt codes with openjdk on windows platform

问题描述:

I built a 32 bit openjdk(jdk8u92) for windows following the instruction from http://openjdk.java.net/groups/build/, the build process is successful without any problems, but when I run a program using swing with fresh build openjdk, which is a simple gui program, the following error occurs:

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)

......

I can find the sun.font.SunFontManager in openjdk, but it seems the class loader failed to load the class...

Any one can help on this?

网友答案:

Finally, I found the root cause of this problem by myself:

This issue is caused by I linked openjdk with a freetype 2.3.5_1 lib which is compiled by gnuwin32, but my local build environment is based on cygwin. So, when running awt java code, the freetype 2.3.5_1 will complain no dependency found(should be a zip2.dll, gunwin32 added it when build freetype 2.3.5_1), whereas openjdk ate this error and thrown sun.font.SunFontManager is not found.

The solution is to build freetype on my own environment using visual studio.

分享给朋友:
您可能感兴趣的文章:
随机阅读: