• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat startup configuration question

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me how I can...


Which file is the advice referring to (and where can I find it)?
And in which part of the file should I make the insertion?

Thanks,
James
[ June 22, 2007: Message edited by: James Hodgkiss ]
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a catalina.bat file in the bin folder of your Tomcat home. You will find a line similar to

set JAVA_OPTS=%JAVA_OPTS% -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="%CATALINA_BASE%\conf\logging.properties"



Add -Djava.awt.headless=true to this existing line. Like this:

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that, if you need to run headless, you're on a Unix box.
In which case, catalina.sh in the same directory is the file you're looking for.

I also assume that you would use "export" and not "set" on a Unix system.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers both of you.

Ben, what does it mean if I 'run headless'? And are there any consequences (apart from dripping on the carpet!...) ?

PS - Yes, I think it is a unix. (The problem I'm having is to do with creating images from byte arrays)
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a byte array that represents an Image, you can create that Image using the java.awt.Toolkit class.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't though - that's the problem...
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean?

What did you try to do?
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See my problem

The problem also occurs for Toolkit.createImage() method as well...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short, that switch lets the JVM know that there is no external imaging
system to leverage when creating or manipulating an image.

For web developers this is usually discovered when the app that was
just built on a Windows desktop (or some type of Unix box with XWindows
running) is put into production on Unix server that is not running
XWindows.

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/
[ June 23, 2007: Message edited by: Ben Souther ]
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers Ben.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've followed the advice, but still having problems. Here's what I've done...


Tomcat config file has been changed to:
CATALINA_BASE=/home/myDomain/www/tomcat
CATALINA_HOME=/usr/share/tomcat4
JAVA_HOME=/usr/lib/j2sdk1.4-sun
JAVA_OPTS="-server -Xms20m -Xmx50m -Djava.awt.headless=true"

export CATALINA_BASE CATALINA_HOME JAVA_OPTS JAVA_HOME

exec /bin/su -s /bin/sh tomcat4 "$CATALINA_HOME"/bin/catalina.sh "$@"


To the beginning of my servlets processRequest method, I've added:
System.setProperty("java.awt.headless", "true");
Toolkit toolkit = Toolkit.getDefaultToolkit();


But that toolkit line throws the following exception:
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.<clinit>(X11GraphicsEnvironment.java:134)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at sun.awt.motif.MToolkit.<clinit>(MToolkit.java:81)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at java.awt.Toolkit$2.run(Toolkit.java:748)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:739)
at myServlets.GetImage.processRequest(GetImage.java:89)


Any ideas?

Cheers,
James
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that setting it from the request might be too late.
You're also setting it before starting Tomcat which should work.

Try pasting this into a JSP and running it.
See if "headless" shows up in the system properties.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've run it, Ben - no mention of a headless property. Here's the output...

Servlet PropertiesTest at /myServlets
java.runtime.name Java(TM) 2 Runtime Environment, Standard Edition
sun.boot.library.path /usr/lib/j2sdk1.4-sun/jre/lib/i386
java.vm.version 1.4.2_04-b05
java.vm.vendor Sun Microsystems Inc.
java.vendor.url http://java.sun.com/
path.separator :
java.vm.name Java HotSpot(TM) Client VM
file.encoding.pkg sun.io
user.country US
sun.os.patch.level unknown
java.vm.specification.name Java Virtual Machine Specification
user.dir /root
java.runtime.version 1.4.2_04-b05
java.awt.graphicsenv sun.awt.X11GraphicsEnvironment
java.endorsed.dirs /usr/share/tomcat4/bin:/usr/share/tomcat4/common/lib
os.arch i386
java.io.tmpdir /home/myDomain/www/tomcat/temp
line.separator
java.vm.specification.vendor Sun Microsystems Inc.
java.naming.factory.url.pkgs org.apache.naming
os.name Linux
sun.java2d.fontpath
java.library.path /usr/lib/j2sdk1.4-sun/jre/lib/i386/client:/usr/lib/j2sdk1.4-sun/jre/lib/i386:/usr/lib/j2sdk1.4-sun/jre/../lib/i386
java.specification.name Java Platform API Specification
java.class.version 48.0
java.util.prefs.PreferencesFactory java.util.prefs.FileSystemPreferencesFactory
os.version 2.4.18-bf2.4
user.home /usr/share/tomcat4
user.timezone Europe/London
catalina.useNaming true
java.awt.printerjob sun.print.PSPrinterJob
file.encoding ANSI_X3.4-1968
java.specification.version 1.4
catalina.home /usr/share/tomcat4
user.name tomcat4
java.class.path /usr/lib/j2sdk1.4-sun/lib/tools.jar:/usr/share/tomcat4/bin/bootstrap.jar
java.naming.factory.initial org.apache.naming.java.javaURLContextFactory
java.vm.specification.version 1.0
sun.arch.data.model 32
java.home /usr/lib/j2sdk1.4-sun/jre
java.specification.vendor Sun Microsystems Inc.
user.language en
java.vm.info mixed mode
java.version 1.4.2_04
java.ext.dirs /usr/lib/j2sdk1.4-sun/jre/lib/ext
sun.boot.class.path /usr/share/tomcat4/bin/bootstrap.jar:/usr/share/tomcat4/common/lib/naming-resources.jar:/usr/share/tomcat4/common/lib/naming-common.jar:/usr/share/tomcat4/common/lib/xmlParserAPIs.jar:/usr/share/tomcat4/common/lib/xercesImpl.jar:/usr/share/tomcat4/common/lib/servlet.jar:/usr/share/tomcat4/common/lib/mysql-connector-java-3.0.14-production-bin.jar:/usr/lib/j2sdk1.4-sun/jre/lib/rt.jar:/usr/lib/j2sdk1.4-sun/jre/lib/i18n.jar:/usr/lib/j2sdk1.4-sun/jre/lib/sunrsasign.jar:/usr/lib/j2sdk1.4-sun/jre/lib/j sse.jar:/usr/lib/j2sdk1.4-sun/jre/lib/jce.jar:/usr/lib/j2sdk1.4-sun/jre/lib/charsets.jar:/usr/lib/j2sdk1.4-sun/jre/classes
java.vendor Sun Microsystems Inc.
catalina.base /home/myDomain/www/tomcat
file.separator /
java.vendor.url.bug http://java.sun.com/cgi-bin/bugreport.cgi
sun.cpu.endian little
sun.io.unicode.encoding UnicodeLittle
sun.cpu.isalist
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What file are you setting it in?
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben, I can't get hold of the server chap, but here's what I asked him previously:

> Can you change a setting in the catalina.sh / catalina.bat configuration file (found in the bin folder of Tomcat home directory)...

His reply was:

> I think our setup is slightly different but I have a similar config file
that sets a JAVA_OPTS environment variable... Basically I think it is a wrapper around catalina.sh to allow for multiple Tomcat users on one machine, each in their own JVM. Although we actually only have one Tomcat running.

Not sure if that's any help, Ben(?). But as soon as I get the exact filename details from him, I'll let you know.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also have some servlets hosted on another server. I also asked that guy to change the headless config prooperty. Here is his response:

> I do not think we will be able to set this property due to the possible load it may cause. You may need to move to a VDS or dedicated server if you need to alter Tomcat in this way.

Are his concerns valid??
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Hodgkiss:
I also have some servlets hosted on another server. I also asked that guy to change the headless config prooperty. Here is his response:

> I do not think we will be able to set this property due to the possible load it may cause. You may need to move to a VDS or dedicated server if you need to alter Tomcat in this way.

Are his concerns valid??



I'm not sure what his concerns are.
I know it is more efficient for the JVM to use the already running windowing system for graphics manipulation (if one is already running) but I don't know how much so.

As with all hosting companies that offer servlet hosting, I wonder if it is just laziness on their part.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just set this variable on my own workstation (Fedora Core) and the headless property showed up in my list of system properties:




I set it in catalina.sh
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ben,

In response to you reply from 28th June...

Long delay, but the server guy has got back to me. His response:


we have a cron job that runs the script below once a day, with parameter
"stop", then a short pause, then again with parameter "start":

This is a shell script called: /usr/share/tomcat4/bin/james.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh

# set the environment

CATALINA_BASE=/home/mydomain.com/www/tomcat
CATALINA_HOME=/usr/share/tomcat4
JAVA_HOME=/usr/lib/j2sdk1.4-sun
JAVA_OPTS="-server -Xms20m -Xmx50m -Djava.awt.headless=true"

export CATALINA_BASE CATALINA_HOME JAVA_OPTS JAVA_HOME

exec /bin/su -s /bin/sh tomcat4 "$CATALINA_HOME"/bin/catalina.sh "$@"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The catalina.sh script is quite a long one that comes with the tomcat4
package and is the standard stop/start script for Tomcat. It is
controlled via environment variables such as those set above.

Basically what this wrapper is doing it giving you your own JVM and
config, limiting the memory usage, and running the JVM as a tomcat4
user. This is so you don't get security problems if several users want
to run Tomcat on the same machine.



Any clues in there?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like they're setting the JAVA_OPTS environment variable in the james.sh script.

Can you get a copy of the catalina.sh file that's being called by james.sh?
I'm wondering if it is also setting a JAVA_OPTS variable and, maybe overriding the one set in james.sh.

Otherwise, I'm running out of ideas.
 
reply
    Bookmark Topic Watch Topic
  • New Topic