图片水印功能在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.
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.
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服务,然后图片水印就可以正常运行。