Ubuntu – tomcat6 restart error: unable to stat java

tomcatUbuntu

Always when I reboot the Tomcat, appears the following message of erro:

/etc/init.d/tomcat6 restart
* Stopping Tomcat servlet engine tomcat6 [ OK ]
* Starting Tomcat servlet engine tomcat6 start-stop-daemon: unable to stat /usr/lib/jvm/java-6-sun/bin/java (No such file or directory)

This happens when I restart tomcat. Then I installed again e when I reboot appears the error.

Best Answer

It looks like you have a broken sun-java symlink in your path to a previous installation which is confusing tomcat's /etc/init.d script.

If you try

file $(which java)

should reply with something like;

java: broken symlink to /some/thing/here

You can try and use the "alternatives" tool to see which Java packages ubuntu thinks are installed like so;

sudo update-alternatives --config java

This will provide a list of the known Java versions installed and allow you to select the default one for your system, alternatives should fix the paths and symlinks auto-magically.

If there is no Java installed, or that does not fix the problem, you can try to reinstall the default openJDK java like so;

apt-get install openjdk-6-jre

and that should fix the alternatives as well, however if it does not, you can run the alternatives command again.

sudo update-alternatives --config java

If you have installed tomcat from a tarball, or non-packaged install of tomcat or java, and not having correct paths set, these steps above might not help, then I would aptitude remove tomcat6 and java, and reinstall both packages.

If you have a preference for Sun java over OpenJDK java then this article contains a link to a script to install Sun java on ubuntu, and also some notes on the other stuff I mentioned. This is required because Ubuntu no longer carries Sun JDK in its default repositories.