tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Running Swing app under Tomcat 6 on Linux
Date Sun, 29 Apr 2012 21:08:08 GMT
Thanks for the response Mark. I've done as you've suggested and moved the env vars to
and explicitly set JAVA_HOME. Setting JAVA_HOME means I no longer need to change the -Djava.library.path
but I still get the same error (X11 not found). 

I definitely have an X11 server running on the server (which is really my laptop; I'm running
all of this locally on my laptop--no remoting). Is it possible that the problem occurs because
I am running Tomcat as a daemon? The command I use to start Tomcat is: 

sudo service tomcat6 start 

I've tried running directly from the console but it doesn't work.  It looks like
/etc/init.d/tomcat6 sets up some env vars before starting Tomcat.  I can try updating my environment
so I can run if you think it worth attempting.


----- Original Message ----- 
From: "Mark Eggers" <> 
To: "Tomcat Users List" <> 
Sent: Saturday, April 28, 2012 6:50:07 PM 
Subject: Re: Running Swing app under Tomcat 6 on Linux 

Comments and questions are in line. Please note I run Fedora / CentOS / Redhat and I'm not
so familiar with Ubuntu. 

----- Original Message ----- 

> From: "" <> 
> To: 
> Cc: 
> Sent: Saturday, April 28, 2012 1:11 PM 
> Subject: Running Swing app under Tomcat 6 on Linux 
> My version info: 
> • Tomcat 6.0.28 
> • Java 1.6 
> • Ubuntu 10.4 
> I have a small debugging/monitoring app written in Java/Swing that I'd like 
> to run inside Tomcat to help with debugging. The app is started by 
> dynamically loading the monitoring class from a webservice running under 
> Tomcat. The works in Windows (multiple flavors) but I'm having problems 
> getting this running on Ubuntu. What I've tried so far: 

What does this give you that monitoring the application via JMX (see VisualVM, jconsole),
and debugging with your favorite IDE (NetBeans, Eclipse, IntelliJ) doesn't give you? You can
actually do both locally as well as remotely (with a little bit of setup). 

> 1) First error I got was an Headless exception. Since the app is a GUI app I 
> can't run in headless mode. After searching around I changed Tomcat's 
> library path (via -Djava.library.path in to point to the 
> client lib (ie. .../java-6-sun- instead of the 
> server lib. 

Try setting JRE_HOME in the environment to point to a JRE installation instead. Or use JAVA_HOME
and point to the JDK. Tomcat will figure things out. 

If your environment is not set up by default to do that (mine is with in /etc/profiles.d),
create and use a script in CATALINA_HOME. In this set any CATALINA_OPTS, JAVA_OPTS,
and other environment variables you need to. 

> 2) After changing the libs the next error was that DISPLAY wasn't set. After 
> setting DISPLAY=0.0 in I get "Can't connect to X11 with 
> DISPLAY=0.0" error. I've tried different values for DISPLAY (e.g. 
> localhost:0.0) and nothing makes a difference. I've also tried fiddling 
> around with the policies in case there's a permissions error. See below for 
> the call stack. 

Are you running an X server? By that, are I mean is Ubuntu showing up in whatever GUI you've
chosen (I guess Gnome 2 is that version's default)? 

If you only have a command line interface, then there's no place to create the screen. You
can play games with a virtual frame buffer, but that will just allow your program to run,
but without any screen output (obviously). 

Again, don't set the DISPLAY environment variable in Set this in in
the bin directory of CATALINA_HOME. There are lots of scenarios here. Three common ones come
to mind. 

1. Local X server 

You're at the console and running in a GUI environment. The display environment variable should
already be set (typically :0.0). If you start Tomcat with your application in this environment,
the GUI interface should just appear. 

2. Remote client, accessing the GUI via a VNC server (such as TightVNC) 

Your display environment should already be set. For example, I'm currently on a remote CentOS
5.8 system via VNC. My DISPLAY environment variable is set to :0.2. If you start Tomcat with
your application in this environment, the GUI interface should just appear in the VNC viewer
(for example TightVNC). 

3. Remote client, X server 

Note that an X server means your PC is serving the screen, keyboard, and mouse to a remote
client (your application). To accomplish this you'll have to have an X server running (if
you're on Windows, try XMing), and you'll have to set the DISPLAY variable appropriately.
Running Java swing applications in this fashion is not very pleasant especially if your program
is graphics-intensive. 

> The webservice app is a simple RESTEasy implementation. Since this works in 
> Windows I'm assuming (perhaps erroneously) that this can work in Linux. Any 
> help would be appreciated. 
> Thanks, 
> DG 
> java . lang . InternalError : Can 't connect to X11 window server using 
> ' : 0 . 0 ' as the value of the DISPLAY variable. 
> sun.awt.X11GraphicsEnvironment.initDisplay(Native Method) 
> sun.awt.X11GraphicsEnvironment.access$100( 
> sun.awt.X11GraphicsEnvironment$ 
> Method) 
> sun.awt.X11GraphicsEnvironment.<clinit>( 
> java.lang.Class.forName0(Native Method) 
> java.lang.Class.forName( 
> java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(

> java.awt.Window.init( 
> java.awt.Window.<init>( 
> java.awt.Frame.<init>( 
> java.awt.Frame.<init>( 
> javax.swing.JFrame.<init>( 
> com.quinsoft.zeidon.objectbrowser.ObjectBrowser.startup( 

This should work just fine if you're running an X server on your Ubuntu system. The DISPLAY
environment variable should be :0.0 (no spaces) for a local machine. 

. . . . just my two cents. 

To unsubscribe, e-mail: 
For additional commands, e-mail: 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message