一、
由于实际所需,在原先系统基础上需要再配置一台服务器作为业务系统,系统环境是linux+tomcat,根据原先的配置情况,将linux系统、tomcat、JDK等环境都安装配置完成,然后把应用程序部署到了tomcat中,但启动后却发现图片验证码无法显示。检查了所有配置和原服务器都是一样的,在catalina.sh中也设置 JAVA_OPTS='-Djava.awt.headless=true'。于是上网查了好多资料,发现和一个libXp.so.6文件有关,最后发现了问题所在。下面简单描述一下原因和解决方法。
如果装了Xwindow,则在/usr/X11R6/lib下有libXp.so.6文件,是一个link文件,指向同目录的libXp.so.6.2文件,libXp.so.6.2文件具有可执行权限,我原有的系统安装了Xwindow所以能正常显示验证码。而新配系统没有装Xwindow缺少libXp.so.6文件,所以没法显示验证码。如果/usr/X11R6/lib下没有libXp.so.6文件,则可拷贝libXp.so.6.2到JDK目录$JAVA_HOME/jre/lib/i386下,建立软链接ln -s libXp.so.6.2 libXp.so.6,设置文件libXp.so.6.2的执行权限即可。这样重启tomcat就可以了,另外在$JAVA_HOME/jre/lib/i386下有一个libawt.so文件,也是必需的,是JDK安装后就有的。
安装:yum install libXp.so.6
cp -af /usr/lib/libXp.so.6.2.0 /usr/java/jdk1.6.0_31/jre/lib/
cd /usr/java/jdk1.6.0_31/jre/lib/
ln -s libXp.so.6.2.0 libXp.so.6
转自:http://lu2002lulu.iteye.com/blog/413783
二、使用以上方法图片还是经常无法打开,提示系统内部错误,日志如下:
May 16, 2013 9:29:44 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NoClassDefFoundError: Could not initialize class 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 java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1135)
at java.awt.image.BufferedImage.getGraphics(BufferedImage.java:1125)
at org.apache.jsp.image_jsp._jspService(image_jsp.java:82)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
at org.j2cms.web.filter.MyStrutsFilterDispatcher.doFilter(MyStrutsFilterDispatcher.java:27)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
解决:http://tcrct.iteye.com/blog/507953
修改${TOMCAT_HOME}/bin/catalina.sh (windows修改catalina.bat)
查到-Djava.io.tmpdir="$CATALINA_TMPDIR"这行,并在这一行下加入:
-Djava.awt.headless=true \
共有七处
执行:
sed -i '/-Djava\.io\.tmpdir=/a\-Djava.awt.headless=true \\' /usr/local/tomcat/bin/catalina.sh
重启tomcat