缺少X11顯示設(shè)置
Exception in thread "AWT-EventQueue-0" java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
解決方案: 在linux的啟動(dòng)文件/etc/profile中增加了 export DISPLAY=localhost:0
缺少X11GraphicsEnvironment
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
解決方案: 在java程序啟動(dòng)時(shí)候态坦,增加了-DJava.awt.headless=true參數(shù)
-DJava.awt.headless=true的作用
對(duì)于一個(gè)Java服務(wù)器來(lái)說(shuō)經(jīng)常要處理一些圖形元素晴氨,例如地圖的創(chuàng)建或者圖形和圖表等。
這些API基本上總是需要運(yùn)行一個(gè)X-server以便能使用AWT(Abstract Window Toolkit捧请,抽象窗口工具集)仰坦。然而運(yùn)行一個(gè)不必要的X-server并不是一種好的管理方式.
有時(shí)你甚至不能運(yùn)行X-server,因此最好的方案是運(yùn)行headless服務(wù)器迈勋,來(lái)進(jìn)行簡(jiǎn)單的圖像處理.
以上轉(zhuǎn)摘自:https://www.cnblogs.com/princessd8251/p/4000016.html
項(xiàng)目中的問(wèn)題回溯
1.問(wèn)題發(fā)生情況:使用poi導(dǎo)出Excel
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
2.完整報(bào)錯(cuò)信息如下:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11FontManager.isHeadless(X11FontManager.java:509)
at sun.awt.X11FontManager.getFileNameFromPlatformName(X11FontManager.java:189)
at sun.font.SunFontManager.initCompositeFonts(SunFontManager.java:3481)
at sun.font.SunFontManager.access$700(SunFontManager.java:65)
at sun.font.SunFontManager$2.run(SunFontManager.java:545)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:376)
at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
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.canDisplayUpTo(Font.java:2060)
at java.awt.font.TextLayout.singleFont(TextLayout.java:470)
at java.awt.font.TextLayout.<init>(TextLayout.java:531)
at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:275)
at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.<init>(AutoSizeColumnTracker.java:117)
at org.apache.poi.xssf.streaming.SXSSFSheet.<init>(SXSSFSheet.java:79)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:656)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:246)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:204)
at org.apache.poi.xssf.streaming.SXSSFWorkbook.<init>(SXSSFWorkbook.java:179)
at com.winning.polaris.engine.view.utils.WExcelUtils.createExcelFile(WExcelUtils.java:181)
at com.winning.polaris.engine.view.utils.WExcelUtils.createRuleCusDataExcle(WExcelUtils.java:165)
at com.winning.polaris.engine.view.rest.controller.EngineRuleController.knowledgeDownload(EngineRuleController.java:645)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)
... 37 more
參考鏈接:
http://www.oschina.net/translate/using-headless-mode-in-java-se
https://www.cnblogs.com/wudi-dudu/p/7871405.html