aspose file tools*
The moose likes Tomcat and the fly likes batik SVG object under tomcat gets: Gtk-WARNING **: cannot open display: Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "batik SVG object under tomcat gets: Gtk-WARNING **: cannot open display:" Watch "batik SVG object under tomcat gets: Gtk-WARNING **: cannot open display:" New topic
Author

batik SVG object under tomcat gets: Gtk-WARNING **: cannot open display:

Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
Hello,

I am developing a (servlet & JSP) webapp running under tomcat.

All was working fine (tomcat serves JSP form to Mozilla Firefox, form data inserted back into mySQL, all processes running on local machine) until I restarted tomcat with the webapp rebuilt with a batik SVG object. Now, the servlet runs, but the (startup JSP) form never loads, and this message appears in catalina.out:

"Gtk-WARNING **: cannot open display:"

The startup JSP attempts to instantiate a javabean, which now (this build) attempts to instantiate the batik SVG object. Prior to this build, the bean instantiates OK. By commenting out only the SVG object instantiation, this build, everything works OK as before.

Just before running into this error, I had received the following error, for the new build, in (log4j's) tomcat.log:

java.lang.ClassNotFoundException: org.w3c.dom.svg.SVGDocument

... this error was encountered as the JSP instantiated the bean, and was fixed by providing the following links in $CATALINA_HOME/common/lib/

xml-apis-ext.jar -> /opt/batik/batik-1.7/lib/xml-apis-ext.jar
batik-svg-dom.jar -> /opt/batik/batik-1.7/lib/batik-svg-dom.jar
batik-util.jar -> /opt/batik/batik-1.7/lib/batik-util.jar
batik-awt-util.jar -> /opt/batik/batik-1.7/lib/batik-awt-util.jar
batik-svggen.jar -> /opt/batik/batik-1.7/lib/batik-svggen.jar
batik-dom.jar -> /opt/batik/batik-1.7/lib/batik-dom.jar

Here's the relevant code in the SVG object:

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.svggen.SVGGraphics2D;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.svg.SVGDocument;

private SVGGraphics2D svggen;
private DOMImplementation dom;
private SVGDocument doc;

... in the constructor:

dom = SVGDOMImplementation.getDOMImplementation();
doc = (SVGDocument) dom.createDocument(null, "svg", null);
svggen = new SVGGraphics2D(doc);

I successfully run this same object in a standalone version (java swing) of this webapp on this PC. The SVG enabled Firefox browser (adobesvg-3.01-linux-i386) successfully loads the SVG images this application produces.

Regarding possible Xserver issues, i'm logged in as me, and start/stop tomcat by way of 'sudo /sbin/service'. The links to the batik jars, and the jars themselves, are owned by user 'tomcat'. I have other tomcat webapps on this box, and they run fine ... this must be some sort of unhappiness about SVG, n'est-ce pas?

Thanks!
Paul

ps:

- Linux 2.6.17-1.2174_FC5 (Fedora Core 5)
- tomcat5-5.5.15-1jpp_6fc
- jdk1.5.0_08
- Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6)
Gecko/20060808
Fedora/1.5.0.6-2.fc5
Firefox/1.5.0.6
pango-text
Authored by: pfenerty
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
Found the problem. Because of this legacy:

"I have successfully run this same object in a standalone version (java swing) of this webapp on this PC."

... my SVG class, so unfortunately, still included the following in its definition:

"extends JPanel"

... so bad.
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
Turns out eliminating the JPanel inheritance is not the problem, but removing it temporarily replaced the problem with more NoClassDefFoundErrors.

The problem ( no startup JSP, catalina.out reports "Gtk-WARNING **: cannot open display:" ) still occurs, when an SVGGraphics2D object is instantiated in the constructor of an object instantiated by the javabean, itself instantiated by the JSP:



public class GViews
{
private SVGGraphics2D svggen;
private DOMImplementation dom;
private SVGDocument doc;

public GViews(GMgrBean gmbean)
{
this.gmbean = gmbean;

dom = SVGDOMImplementation.getDOMImplementation();
doc = (SVGDocument) dom.createDocument(null, "svg", null);
// svggen = new SVGGraphics2D(doc);

}


... the above does not trigger the Gtk-WARNING, and the JSP loads OK. Uncomment that last line, and the problem manifests (but only in the webapp ... the code works fine in a swing app).

Any thoughts?

Thanks again ...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
It sounds like the server you are trying to deploy on can't support that graphics format. I vaguely recall that you want the server to run "headless". I found this discussion by searching for "java servlet headless."

Bill
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
good stuff! thanks so much.

much else to do today, but I will post back eventually regarding resolution.
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
Following the standard solution:

Ernest Friedman-Hill, sheriff and author: "You can run Xvfb, the X virtual frame buffer, as the tomcat user on display 1 (or any other number besides 0) and then set DISPLAY=:1 in Tomcat's environment. It's basically a mini X server, and AWT will be perfectly happy with it.


... for Fedora Core 5

[pf@gezora ~]$ sudo yum -y install xorg-x11-server-Xvfb.i386
[root@gezora logs]# su tomcat -c "/usr/bin/Xvfb :1 -screen 0 800x600x24 "&
[root@gezora logs]# diff /etc/tomcat5/tomcat5.conf /etc/tomcat5/tomcat5_conf_orig
36d35
< export DISPLAY=:1.0


... I get here:

GMgrServlet threw exception java.lang.Error: Graphics2D not implemented. Cairo was not found or disabled at configure time
at gnu.java.awt.peer.gtk.GdkGraphics2D.<clinit>(lib-gnu-java-awt-peer-gtk.so.7) at java.lang.Class.initializeClass(libgcj.so.7)
at gnu.java.awt.peer.gtk.GdkGraphicsEnvironment.createGraphics(lib-gnu-java-awt-peer-gtk.so.7) at java.awt.image.BufferedImage.createGraphics(libgcj.so.7)
at org.apache.batik.svggen.SVGGraphics2D.<init>(Unknown Source) at org.apache.batik.svggen.SVGGraphics2D.<init>(Unknown Source)
at glucoseMgr.GViews.<init>(GViews.java:73) at glucoseMgr.GMgrBean.<init>(GMgrBean.java:68)


... well, cairo is installed

[pf@gezora ~]$ rpm -qa | grep -i cairo
pycairo-1.0.2-1.2.1
cairo-java-1.0.5-1.fc5
cairo-devel-1.0.4-1
cairo-1.0.4-1


... but then there's this:

someone in 'ProjectX':
> Exception in thread "main" java.lang.Error: Graphics2D not implemented.
> Cairo was not found or disabled at configure time
> at gnu.java.awt.peer.gtk.GdkGraphics2D.<clinit>(lib-gnu-java-awt-peer-gtk.so.7)
[snip]
The only way that I've found to fix this is to use Sun's JVM.


.... this FC5 box came with gcj as default, but i'm using the jdk:

[pf@gezora ~]$ /usr/sbin/alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
+ 2 /opt/jdk1.5.0_08/bin/java
Enter to keep the current selection[+], or type selection number:


... and tomcat believes this to be true:

[pf@gezora webapps]$ sudo /sbin/service tomcat5 start
Starting tomcat5:
Running /etc/profile
Using CATALINA_BASE: /usr/share/tomcat5
Using CATALINA_HOME: /usr/share/tomcat5
Using CATALINA_TMPDIR: /usr/share/tomcat5/temp
Using JRE_HOME: /opt/jdk1.5.0_08


... so ... why is tomcat using gcj? because of xvfb? how to make it stop?
... and thanks again ...
Paul Fenerty
Greenhorn

Joined: May 06, 2005
Posts: 23
well, the webapp runs fine, given Xvfb, on an old redhat 7.3 box (tomcat5.0, jdk1.4).

I found this, again regarding Project-X, the (Java) MPEG2 transport stream tool, trying to run on FC5:

"ProjectX ( Java ) is being suggested as a useful tool to work around
this. An rpm exists (Suse) that is said to work on FC5 but it needs
jakarta-commons-net, versions of which exist for older redhat and for
mandriva but apparently not for fc5.
Typing the start command projectx.sh produces ... a list of Exceptions
starting:
Graphics2D not implemented. Cairo was not found or disabled at configure
time....
before returning to the usual shell prompt. Cairo _is_ installed.
I suppose the absence of a jakarta-common-net rpm for fc5 is saying
something."

... doesn't sound hopeful. Seems like this may be more of a fedora problem than a tomcat problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: batik SVG object under tomcat gets: Gtk-WARNING **: cannot open display: