Using Tomcat (or anything Java) on a virtual server

When it comes to serving web pages, two technical trends (among others) are prevalent: virtual servers and server side Java. To the end user, both are completely transparent, and even the server administrator might forget the fact that his server is virtual, because from experience he can tell that it behaves exactly as a physical server. It seems only natural (not even worth mentioning) to combine both trends.

In fact, this is not as easy as you might guess. Lets say you have a virtual server, running Ubuntu 9.04, and have installed sun-java6-jdk, and decompressed tomcat-6.0.18 somewhere.  The most trivial way to start it is


which is likely to tell you something like

Using CATALINA_BASE: /(...)/tomcat-6.0.18
Using CATALINA_HOME:   /(...)/tomcat-6.0.18
Using CATALINA_TMPDIR: /(...)/tomcat-6.0.18/temp
Using JRE_HOME:       /usr/lib/jvm/java-1.6.0-sun

While this might seem as if the server was started successfully, nothing really happened. A look into /(…)/tomcat-6.0.18/logs/catalina.out might show something like

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

This is due to the way memory management is handled on virtual servers, which you can read here. It has nothing to with the actual amount of RAM that Tomcat needs, it also appears that a simple command like „java -version“ tries to allocate more memory then it is allowed to (284 MB on my vServer). Several sites recommend to set the -Xmx option when starting Java, mostly by modifying scripts which are not made to be modified. Some others advise changing /etc/java-1.5.0-sun/jvm.cfg to prefer the client VM over the server VM, or even to delete the server VM and symlink it to the client version.

Not only is it highly absurd that you have to use a client VM on a server just because the server is not capable of running the server VM, but it also is impossible, because Java 6 seams to have no client implementation on 64 bit processors – and of course virtual servers run on 64 bit machines (mine has at least 44 GB of RAM, how would it handle this on 32 bit?).

Using -Xmx seems to work, even though you do not want to change each and every script that calls java or javac. To encompass this, you can set the environment variable JAVA_OPTS to something like JAVA_OPTS=“-Xms10m -Xmx256m“, which is definitely picked up by Tomcat, and maybe used by other scripts which run java or javac. Sadly, many scripts do not, and there seems to be not way to make java „just run“ on a virtual server.

With the proper options, java does run, but Tomcat does not. It keeps on saying

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

I started writing this blog post hoping that I would conclude with a working solution, but as it seems right now, I just cannot find one. I will keep trying, possibly not only searching the web but also posting questions like I did on and in the end I will update this post to reflect the solution.

One more note: whil this works for calls to the „java“ binary, it does not for „javac“, which does not directly accept -Xms and -Xmx. You have to use -J-Xms and -J-Xmx instead.

I’m currently out of order…

…and so is my blog.

(I know that „out of order“ applies to technical stuff, an normally one would say „I’m currently too busy“. But depending on how busy you are, there isn’t a clear distinction anyway)

It might seem as if my blog was dead even before it started living. But rest assured, this is just a temporal break. Currently, my studies and other affairs are so demanding, that blogging just doesn’t fit in. It was even hard to find a moment to post this post, which just emphasizes its message. But as I think that having time for blogging is a crucial right of any human being, I’m constantly trying to change my life in a way that will give me that time back (and time for other things, of course).

There are so many things to say, mostly unwritten but well thought about, so that in the not-so-distant future, when I’ll have the necessary time, there’s no risk of running out of ideas. To make the waiting worthwhile, I’ll present a (not even complete) List of topics that I want to cover soon:

  • What does it take to be an inventor?
  • Tin-openers as a model for software tools
  • When the food is smiling at you
  • Is portability a means to an end, or an end in itself?
  • Is OpenStreetMaps an every-day-alternative to e.g. Google Maps?
  • How everybody can contribute to OpenStreetMap without even leaving his home.
  • Make simple things simple, or: the theory of computational complexity applied to human beings (for both computer-related and real-world tasks)
  • How it feels to fail at the most simple tasks
  • The problem of fuzzy groups in social interaction and web administration
  • The pros and cons of tuition fees (Studiengebühren)

I can’t guarantee that each topic will be covered, or that I will manage to do this any time soon, but if some of this sounds interesting to you, you should consider coming back or subscribing to my RSS feed.

PS: One note on the choice of language: This will be an english blog. But if I have something of interest only to a limited, german-only audience, I fall back to using german. If you’re an english speaker, you probably don’t miss anything.