在java中使用awt在服务器上处理图片的时候发现有错:
第一遍执行
500 Servlet Exception
java.lang.InternalError: Can't connect to X11 window server using ':0.0'
as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
at com.lodesoft.ipniii.club.tool.AlbumTool.createSmallThumb(AlbumTool.java:793)
at com.lodesoft.ipniii.club.test.action.UpdateAllPhotoAction.perform(UpdateAllPhotoAction.java:82)
at org.apache.struts.action.Action.execute(Action.java:420)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:113)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:262)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:315)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:353)
at com.caucho.util.ThreadPool.run(ThreadPool.java:302)
at java.lang.Thread.run(Thread.java:534)
--------------------------------------------------------------------------------
Resin-3.0.6 (built Tue, 20 Jan 2004 09:46:57 PST)
然后刷新这个页面
500 Servlet Exception
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.image.BufferedImage.createGraphics(BufferedImage.java:1041)
at com.lodesoft.ipniii.club.tool.AlbumTool.createSmallThumb(AlbumTool.java:793)
at com.lodesoft.ipniii.club.test.action.UpdateAllPhotoAction.perform(UpdateAllPhotoAction.java:82)
at org.apache.struts.action.Action.execute(Action.java:420)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:113)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:262)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:315)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:353)
at com.caucho.util.ThreadPool.run(ThreadPool.java:302)
at java.lang.Thread.run(Thread.java:534)
--------------------------------------------------------------------------------
Resin-3.0.6 (built Tue, 20 Jan 2004 09:46:57 PST)
我们的服务器上没有安装xwindows,但是安装了XFree86的相关包。web server用的是 Resin 306 ,现在找到了解决方法。
1:安装XFree86-Xvfb-4.3.0-2.i386.rpm。如果什么XFree86的相关包都没有,那就要弄来装一装了。起码的libs是要有的。
2:使用两个命令:
------------------------------------
Xvfb :0 -screen 0 800x600x16 & 启动Xwindows的虚拟设备
export DISPLAY=localhost:0.0 配置本地环境
------------------------------------
运行顺序先后没有太大的关系。
注意的是 Xvfb :0 -screen 0 中的两个0的参数和后面 DISPLAY=localhost:0.0 中的两个0是对应的。Xvfb实现的应该是后台虚拟拟图形界面环境。
3:可以把这两个命令做成启动就运行的脚本,也可以在启动Resin的时候调用起来,我用的后者
修改resin ./bin 目录下的httpd.sh 在JAVA_HOME 配置项前加入
Xvfb :0 -screen 0 800x600x16 &
export DISPLAY=localhost:0.0
4:其实没有什么第四,因为这样就可以啦。