java poi linux,Linux下Tomcat中POI导出异常:java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment...

POI导出Excel出现java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment异常

问题描述:

项目在window中使用POI导出Excel没有任何问题,而到linux中使用POI导出Excel出现:java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment异常信息

异常信息如下:

Caused by: java.lang.NoClassDefFoundError: sun/awt/X11GraphicsEnvironment

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Class.java:169)

at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)

at sun.font.FontManager.initSGEnv(FontManager.java:1094)

at sun.font.FontManager.findFont2D(FontManager.java:1756)

at java.awt.Font.getFont2D(Font.java:452)

at java.awt.Font.canDisplay(Font.java:1835)

at java.awt.Font.canDisplayUpTo(Font.java:1901)

at java.awt.font.TextLayout.singleFont(TextLayout.java:451)

at java.awt.font.TextLayout.(TextLayout.java:509)

at com.ai.mapp.service.table.utils.ReportExportExcel.exportExcel(ReportExportExcel.java:70)

at com.ai.mapp.action.business.ReportDataAction.expReportExcel(ReportDataAction.java:362)

... 56 more

解决方案:

在tomcat配置文件catalina.sh文件中添加 CATALINA_OPTS="-Djava.awt.headless=true"

catalina.sh添加之后如下:

# LOGGING_CONFIG (Optional) Override Tomcat's logging config file

# Example (all one line)

# LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"

#

# LOGGING_MANAGER (Optional) Override Tomcat's logging manager

# Example (all one line)

# LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"

#

# $Id: catalina.sh 1146097 2011-07-13 15:25:05Z markt $

# -----------------------------------------------------------------------------

JAVA_OPTS="-Xms512m -Xmx19500m"

CATALINA_OPTS="-Djava.awt.headless=true"

# OS specific support. $var _must_ be set to either true or false.

cygwin=false

os400=false

darwin=false

case "`uname`" in

CYGWIN*) cygwin=true;;

OS400*) os400=true;;

Darwin*) darwin=true;;

esac

# resolve links - $0 may be a softlink

PRG="$0"

while [ -h "$PRG" ]; do

你可能感兴趣的:(java,poi,linux)