File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes tomcat with Xvfb on Mac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat with Xvfb on Mac" Watch "tomcat with Xvfb on Mac" New topic
Author

tomcat with Xvfb on Mac

Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12
To get Xvfb working I've added the following code to my catalina.sh script for tomcat on Mac Leopard

DISPLAY=localhost:1.0
export DISPLAY

Then further down in the same script I have the command
/usr/X11/bin/Xvfb :1 -screen 0 1152x900x8

This all goes fine up to a point and I can work.
But as soon as I call some code that needs Xvfb, the Tomcat bootstrap process opens up in its own window, which if closed, shuts down Tomcat.

If I leave the bootstrap window open, I can at least continue working, but this behaviour is a little strange, and I would like solve this, keeping Tomcat working in the background.
Anybody got any ideas what's happening?

Thanks for any help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
You want to start Tomcat in headless mode by way of specifying the
"-Djava.awt.headless=true" property. One way of doing that is to initialize the CATALINA_OPTS variable in the bin/catalina.sh script with that value.


Ping & DNS - updated with new look and Ping home screen widget
Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12
Thanks very much, Ulf for your reply.

We spent a lot of time on trying to get headless working and eventually gave up and fell back on Xvfb, which is on our production (Linux) server, so ideally I'd like my test (Mac) server to do the same.

However:
The strange bit is that here on my test (Mac) machine, headless was working, so I wasn't bothering with Xvfb. But suddenly one day a week ago, headless stopped working for no apparent reason. Though I think I know why, and here perhaps you can help.

Headless seems installed by default with Tomcat for logging: can't quite see why but there you are. Because it's part of the options for logging.
Here's the line in catalina.sh
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true"

I've just installed and started using Log4j, and I can only think that this is why headless started complaining.

Does any of this make sense to you? Thanks again.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
No, can't help you there - I've never dug into the Tomcat logging stuff. Also, my catalina.sh script (from Tomcat 5.5) doesn't have the headless property in JAVA_OPTS, so the setup may be slightly different.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

That's not a logging option, those are 2 separate VM definition options. One defining the logging manager, and the other instructing interested parts of the system that you intend to employ the headless mode of operation.

Headless isn't supposed to be that touchy, although it's possible that if you have an app that making use of more esoteric graphics services, the headless emulator might not support them. Xvfb, if my feeble memory serves is just a thin pass-through to the server's video card without the actual display services provided when you have an X server on the server machine.


Customer surveys are for companies who didn't pay proper attention to begin with.
Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12
Thank you Tim, for clearing up the logging business.
Because it made absolutely no sense that graphics and logging had anything to do with each other.

So I'm still stuck with this problem.
Tomcat starts in the background on startup, from a Macintosh plist, and it all works.

Then as soon as a some code that needs graphics starts (one of them measures photo sizes for example), then a tomcat bootstrap window opens up.
And if I close that window, Tomcat stops with it. I'm completely stumped.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Malcolm Warren wrote:
Then as soon as a some code that needs graphics starts (one of them measures photo sizes for example), then a tomcat bootstrap window opens up.
And if I close that window, Tomcat stops with it. I'm completely stumped.


I don't know what a "tomcat bootstrap window" is, but my guess is that it's a stdout/stderr console. One of the reasons that System.out/System.err shouldn't be used except for stand-alone Java applications, not webapps, applets, jme midlets or other non-Unix type programs. But you probably don't have source code for the offending component, so you'll have to work around that defect.

You should be able to eliminate the pop-open window by setting the Tomcat startup to redirect stdout/stderr to /dev/null or to a file.
Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12
Actually Tim, I think you're right. Thanks for the idea. That ought be it.
It's the call to launch Xvfb that needs to finish with > /dev/null
I've copied the line from our production server which looks like this:

/usr/X11/bin/Xvfb :1 -screen 0 1152x900x8 > /dev/null &

But for some reason the window still opens, which is very perplexing.
I'm sure this is on the right track, however.



Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Hi Malcolm,

The standard Mac OS X JVM doesn't use X/Windows at all; it uses the native Mac GUI directly, just as the Windows JVM uses the native Windows APIs. The Xvfb trick works on Linux, Solaris, and other UNIXy OSs, but (despite its UNIX underpinnings) Mac OS X is not in this category. Running Xvfb will have no effect on Tomcat or any other Mac JVM. DISPLAY is ignored, as it has no meaning on this OS.

Now, as far as this Tomcat "bootstrap window," as other have said, we don't know what that is. If you launch Tomcat by hand, then stdout should go to the terminal you launched it from. Can you tell us *exactly* how you're starting tomcat, and maybe show us a screenshot of the "bootstrap window"?


[Jess in Action][AskingGoodQuestions]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Malcolm Warren wrote:Actually Tim, I think you're right. Thanks for the idea. That ought be it.
It's the call to launch Xvfb that needs to finish with > /dev/null
I've copied the line from our production server which looks like this:

/usr/X11/bin/Xvfb :1 -screen 0 1152x900x8 > /dev/null &

But for some reason the window still opens, which is very perplexing.
I'm sure this is on the right track, however.





Try adding a "2> /dev/null".
Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12

Try adding a "2> /dev/null".


Thanks for the idea, and I've tried it, but the window still opens. Here's the line in catalina.sh
/usr/X11/bin/Xvfb :1 -screen 0 1152x900x8 2> /dev/null &

I also ran Xvfb from a macintosh plist with the logging directed to the tomcat logs: same problem.
The startup messages came out in the tomcat logs all right, but it still opened a window.

And the other question is: why is the window entitled 'org.apache.catalina.startup.Bootstrap'? (i.e. it's a Tomcat window).
The window only opens when Xvfb is needed, but it doesn't appear to be an Xvfb window.

The only good thing in all this is that at least the graphics programmes do their job. But it causes all sorts of problems (Eclipse can't find tomcat for debugging when the window is open, for example, so I have to close it and restart Tomcat).
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

When I said "try adding a 2> /dev/null", I didn't mean remove the other route to dev null. "1>" (or no number) is for stdout, "2>" is for stderr. You may need to lose both of them.

Other than that, there's some stuff in there that's just plain weird. Like it's spawning independent processes and not inheriting environments.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Malcolm -- SEE MY POST ABOVE. This is a wild goose chase, my friend.
Malcolm Warren
Greenhorn

Joined: Mar 22, 2009
Posts: 12
Ok, Earnest, looks like you're right - because whatever I've done so far it looks like Tomcat is saying: "I need graphics here, so I'll open up in a graphics environment". Which explains why it's a tomcat window, and not an Xvfb window - which the system ignored.

Is there any solution, as far as you know, to the problem? For some reason headless doesn't work at all for the only two cases where I need graphics.

1) Where we measure new photos on our system, so that the html pages know in advance the size of photos
2) Creating .pdfs

Any idea why headless won't deal with two normal graphics needs like these?

Meanwhile thanks to everyone for the help and attention.


Yoichi Takayama
Greenhorn

Joined: Nov 26, 2010
Posts: 1
Hi

Have you tried the Xvfb (putting xvfb.server script in /etc/init.d) idea from Sun?

http://developers.sun.com/solaris/articles/solaris_graphics.html

I have the same problem with Tomcat when I try to use IDL-Java Export Bridge within my Servlet code. I think that the Bridge glue code tries to launch IDL VM (which is an XWindow application) and causes "Unable to open XWindows display" error.

My target system is CentOS, but the -Djava.awt.headless=true did not work on Mac OS X (development environment). So, I presume that it won't work on CentOS, either.

I haven't quite figured it out yet to see how Tomcat will start using the Xfvb with this xvfb.server script.

Thanks,
Yoichi

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tomcat with Xvfb on Mac
 
Similar Threads
error in Swing based app when accessing via Xmanager
Displaying graphics in a JSP
Getting errors while trying to get graphics environment
error while using BufferedImage class in servlet
Timer in popup window in javascript