红联Linux门户
Linux帮助

Linux下java.awt处理

发布时间:2006-08-11 09:40:57来源:红联作者:benny_feng
环境:Linux + Websphere5.1 + db2

图片水印功能在window平台上运行正常,到Linux平台上,程序报错,找不到awt类.
我在websphere的起动文件中../bin/startServer.sh文件中增加

-Djava.awt.headless=true (注:jdk1.4或更高版本才可以加)

"$JAVA_HOME"/bin/java \
$DEBUG \
-Dws.ext.dirs="$WAS_EXT_DIRS" \
-classpath "$WAS_CLASSPATH" \
-Dwas.install.root="$WAS_HOME" \
-Djava.awt.headless=true \
$USER_INSTALL_PROP \
com.ibm.ws.bootstrap.WSLauncher \
$SHELL "$CONFIG_ROOT" "$WAS_CELL" "$WAS_NODE" "$@"


增加如上代码后,java.awt类是可以运行了,但是以报出一个新的错误,错误日志如下:

SRVE0026E: [Servlet 错误]-[Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.]: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 at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:161).null(Unknown Source)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java(Compiled Code))
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:90)
at at sun.awt.motif.MToolkit.(MToolkit.java:109).null(Unknown Source)
at java.lang.Class.forName1(Native Method)
at java.lang.Class.forName(Class.java(Compiled Code))
at java.awt.Toolkit$2.run(Toolkit.java:754)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:745)

产生以上问题的主要原因是DISPLAY的设置,同样在webspere /bin/startServer.sh文件中加入以下代码

PLATFORM=`/bin/uname`
case $PLATFORM in
AIX)
EXTSHM=ON
LIBPATH="$WAS_LIBPATH":$LIBPATH
export LIBPATH EXTSHM ;;
Linux)
LD_LIBRARY_PATH="$WAS_LIBPATH":$LD_LIBRARY_PATH
export DISPLAY=127.0.0.1:0
export LD_LIBRARY_PATH ;;
SunOS)
LD_LIBRARY_PATH="$WAS_LIBPATH":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH ;;
HP-UX)
SHLIB_PATH="$WAS_LIBPATH":$SHLIB_PATH
export SHLIB_PATH ;;
esac


然后重新启动websphere服务,然后图片水印就可以正常运行。
文章评论

共有 0 条评论