# "Can't connect to X11 window server using ':0.0'"

## mc717990

I've got an issue getting tomcat to use the X server as started by xdm.  I NEED to use X vs. headless due to using the awt components which don't work with a headless environment.  (i.e. so java.awt.headles=true will NOT work)  The trick is this - xdm is running, xhost shows this:

INET:localhost

LOCAL:

but, still no luck with tomcat accessing the local X server.  Here's some other details:

```

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.access$000(X11GraphicsEnvironment.java:53)

        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:142)

        at java.security.AccessController.doPrivileged(Native Method)

```

and a later message I get which I'm GUESSING at this point is due to the initial error of X not working:

```

2007-05-21 10:01:02 ApplicationDispatcher[/birt] Servlet.service() for servlet jsp threw exception

java.lang.NoClassDefFoundError

        at sun.print.UnixPrintServiceLookup.getPrintServices(UnixPrintServiceLookup.java:351)

        at javax.print.PrintServiceLookup.getServices(PrintServiceLookup.java:359)

        at javax.print.PrintServiceLookup.lookupPrintServices(PrintServiceLookup.java:105)

```

Any suggestions on this?  For a more detailed bit of info, I'm trying to get BIRT working properly (2.2M6 release) with charts support.

Thanks!

Jason

----------

## RayDude

Dumb questions:

1. Has the X windows user done a "xhost +"?

2. Does the X window driver have a -nolisten tcp option? If it does, X will ignore packets from the world only taking packets from localhost.

For number 2 you can just run, "ps -ef | grep X" on the X display to see the options running with X. If nolisten tcp is there, that's your culprit.

If you already knew these things, then sorry I killed your unanswered post status.

Raydude

----------

## mc717990

 *RayDude wrote:*   

> Dumb questions:
> 
> 1. Has the X windows user done a "xhost +"?
> 
> 2. Does the X window driver have a -nolisten tcp option? If it does, X will ignore packets from the world only taking packets from localhost.
> ...

 

Done xhost + and also done xhost +localhost, xhost +local:, sudo tomcat -c sh "xhost +localhost ; xhost +local:", etc.

The X window server is just /usr/bin/X vt7

If I run the tomcat process as root, it works fine.  It's just when it's started as tomcat that the process fails.

Thanks!

Jason

----------

## RayDude

 *mc717990 wrote:*   

>  *RayDude wrote:*   Dumb questions:
> 
> 1. Has the X windows user done a "xhost +"?
> 
> 2. Does the X window driver have a -nolisten tcp option? If it does, X will ignore packets from the world only taking packets from localhost.
> ...

 

Its obviously a permissions thing. Is it possible that as a plain user, java doesn't have permission to access the display?

Sorry I can't be any more help.

Raydude

----------

## mc717990

 *RayDude wrote:*   

>  *mc717990 wrote:*    *RayDude wrote:*   Dumb questions:
> 
> 1. Has the X windows user done a "xhost +"?
> 
> 2. Does the X window driver have a -nolisten tcp option? If it does, X will ignore packets from the world only taking packets from localhost.
> ...

 

The thing is, it's not java, it's tomcat.  Tomcat starts the java process.  And a sudo -u tomcat -c sh "xhost" reports it can connect to the X server.  SO, I'm wondering at this point if it's something in how tomcat is started on gentoo, since if I start the tomcat process by hand as root, it works fine.  I've not tried starting the tomcat process directly as tomcat, but that'll be the next thing I try.

Either way, sounds like the gentoo tomcat startup scripts are definitely buggy...

Jason

----------

## mc717990

Some more details - looks like it's an issue with the gentoo init scripts.  Somehow or other that is.  Here's what I've discovered:

```

DISPLAY=:0.0 /opt/tomcat5/bin/catalina.sh start"

sudo -u tomcat sh -c "DISPLAY=:0.0 /bin/sh /opt/tomcat5/bin/catalina.sh start"

```

all work fine.  It's ONLY when I try and start the server up using the gentoo init scripts that the server fails to connect to the X11 server, and causes so many of the problems I'm facing.  NOTE!  This is with tomcat5.  I've not even begun to try and debug tomcat-5.5 yet, which runs java directly from what I can tell, and I don't think works at the moment.  At least with the earlier version, I could bypass the init scripts... *sigh*  Gentoo really seems to be screwed up when it comes to tomcat.

----------

## RayDude

 *mc717990 wrote:*   

> Some more details - looks like it's an issue with the gentoo init scripts.  Somehow or other that is.  Here's what I've discovered:
> 
> ```
> 
> DISPLAY=:0.0 /opt/tomcat5/bin/catalina.sh start"
> ...

 

I suggest you file a bug report, the gentoo developers are usually very receptive. Your setup is probably a case they haven't considered and helping you will make their scripts more robust.

Raydude

----------

## mc717990

 *RayDude wrote:*   

>  *mc717990 wrote:*   Some more details - looks like it's an issue with the gentoo init scripts.  Somehow or other that is.  Here's what I've discovered:
> 
> ```
> 
> DISPLAY=:0.0 /opt/tomcat5/bin/catalina.sh start"
> ...

 

SO, did some more debugging.  The newest versions of the init scripts for tomcat still have the issues.  Basic, it looks like start-stop-daemon doesn't let the process connect to X11, or something along those lines.  I modified the init script, and did

```

sudo -u tomcat sh -c "DISPLAY:0 ${JAVA_HOME}/bin/java ${OPTS_CP} ${CATALINA_ARGS} ${TOMCAT_START} >> ${CATALINA_BASE}/logs/catalina.out 2>&1 & "

```

instead of virtually the same thing.  Basically, I just changed

```

start-stop-daemon ${arguments} --exec ${executor} -- 

to

sudo -u tomcat sh -c "DISPLAY:0 ${JAVA_HOME}/bin/java

```

which is what, as far as I can tell, the init script was really doing anyways.  I need to post a bug report, but I've been lazy about it since I got it working for myself.

----------

