Java cannot handle graphics under Linux solution sharing

  • 2020-04-01 02:06:31
  • OfStack

Java calls the local graphics library for graphics processing. When using Java for graphics processing (e.g., image scaling, image signing, report generation), running on Windows is fine. When porting programs to Linux/Unix, there may be an error where the graphics do not appear.

"Can't connect to X11 window server" this is because Linux graphics requires an X server server.

Solutions:

1. If a graphical interface is installed on the server, this can be done by setting the environment variable: DISPALY=127.0.0.1:0.0.

2. If you do not have a graphical interface installed, you can add the parameter -djava.awt.headless =true at Java runtime.

3. Use the PJA library to replace the local graphics processing library.

The modification of Tomcat is as follows:

Open %Tomcat_home%/bin/catalina.sh and add: -djava.io.tmpdir ="$CATALINA_TMPDIR" to the script for starting Tomcat

"$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS
- Djava. Endorsed inside. Dirs = "$JAVA_ENDORSED_DIRS"
- the classpath "$classpath"
- Dcatalina. Base = "$CATALINA_BASE"
- Dcatalina. Home = "$the CATALINA_HOME"
- Djava. IO. Tmpdir = "$CATALINA_TMPDIR"
- Djava. Awt. Headless = true
Org. Apache. Catalina. Startup. The Bootstrap "$@" start
> > "$CATALINA_BASE/logs/catalina. Out 2 > & 1 &
If [! -z "$CATALINA_PID"]; then
Echo $! > $CATALINA_PID fi
Fielif ["$1" = "stop"]; then

After saving, reboot to process the graphics.


Related articles: