# Boot time JAVA_HOME not set for TOMCAT

## wiggly

Hi all,

Not sure if this is the right place for this but I think so.

Been using Gentoo for a few months. Got a 1.1a box and have recently tried to get jboss/tomcat/apache all up and running.

After a reboot the JAVA_HOME variable is not set on boot for the tomcat rc script, jboss rc script or my environment.

Neither Tomcat nor JBoss start correctly. If I watch a boot locally I see Tomcat complain about JAVA_HOME not being set, JBoss doesn't check.  Either way the JAVA_HOME var is not set for either of them during the boot sequence.

Currently trying to get this to work with;

- blackdown-jdk 1.3.1-r8

- jboss 3.0.6

- tomcat 4.1.24

When I log in and echo $JAVA_HOME I get nothing.

Sourcing /etc/profile does not help

If I do an env-update and log in againJAVA_HOME is correctly set, this does not of course help to start JBoss and Tomcat on boot though.

Here is the edited output from env after I login, you can see that all the tomcat vars are there and all the java ones too, except for JAVA_HOME.

Below is my environment (slightly edited to be more readable) immediately after login;

```

wiggly@leon wiggly $ env

USER=wiggly

HOME=/home/wiggly

PATH=/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/2.95:/usr/X11R6/bin: /opt/blackdown-jdk-1.3.1/bin:/opt/blackdown-jdk-1.3.1/jre/bin:/usr/share/omniORB/bin/scripts

PWD=/home/wiggly

SHELL=/bin/bash

CATALINA_HOME=/opt/tomcat

CATALINA_BASE=/opt/tomcat

CATALINA_LIBDIR=/usr/share/tomcat/lib

CATALINA_OUT=/var/log/tomcat/catalina.log

CATALINA_USER=tomcat

TOMCAT_START=start

TOMCAT_STOP=stop

JAVA_HOME=

JAVAC=/opt/blackdown-jdk-1.3.1/bin/javac

JDK_HOME=/opt/blackdown-jdk-1.3.1

CLASSPATH=/opt/blackdown-jdk-1.3.1/jre/lib/rt.jar:.:/opt/blackdown-jdk-1.3.1/jre/lib/rt.jar:

.::/usr/share/tomcat/lib/lib:/usr/share/tomcat/lib/lib

wiggly@leon wiggly $ 

```

Below is my environment after an env-update and logging in again;

```

wiggly@leon wiggly $ env

USER=wiggly

HOME=/home/wiggly

PATH=/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/2.95:/usr/X11R6/bin: /opt/blackdown-jdk-1.3.1/bin:/opt/blackdown-jdk-1.3.1/jre/bin:/usr/share/omniORB/bin/scripts

PWD=/home/wiggly

SHELL=/bin/bash

JAVA_HOME=/opt/blackdown-jdk-1.3.1

JAVAC=/opt/blackdown-jdk-1.3.1/bin/javac

JDK_HOME=/opt/blackdown-jdk-1.3.1

CLASSPATH=/opt/blackdown-jdk-1.3.1/jre/lib/rt.jar:.

wiggly@leon wiggly $ 

```

You can see that in the second one the Tomcat env vars have disappeard...odd.

I'm 99.99999% sure my java setup is correct, if anyone has any ideas or wants more info to help me sort this out then please, please, please reply...*sob*

I love the way Gentoo handles rc scripts, right up until the point it breaks. I really don't want to have to add a whole bunch of shit to my local start script to make this work even though I may have to start doing that because I need a machine that restarts cleanly...

Thanks in advance,

  - Werm

EDIT:  Added a space to the PATH and CLASSPATH lines for wordwrapping.  -- pjp

----------

## pjp

Moved from Installing Gentoo.

----------

## wormie

I've had a similar problem, using Tomcat 4.0.6 & the Sun JDK. All the paths are set fine the rest of the time, but Tomcat could never seem to find JAVA_HOME while booting.

I start Tomcat from within my /etc/init.d/apache script, so your mileage may vary, but the lazy fix was just explicitly exporting JAVA_HOME at the beginning of the start section like so:

```
start() {

        ebegin "Starting tomcat"

        export JAVA_HOME='/opt/sun-j2sdk-1.4.1'

        /opt/jakarta/tomcat/bin/startup.sh

        ebegin "Starting apache"

        and so on...

```

It's almost certainly not the best way to do it, but it works here.

----------

## wiggly

Yeah cheers, I think I'm going to add something like;

```

export JAVA_HOME=`java-config --jdk-home`

```

So that it works when I change VM as well.

I would really rather like to find someone who deals with the maintenence of this though to find out why JAVA_HOME isn't getting set properly during the boot sequence...

  - Werm

----------

## DNH

Take a look at '/etc/env.d/20java'  The command listed in the second commented line will update this file and properly set your java locations at boot.  Note that you want to edit the second line to reflect the actual java version you are using.  Hope that helps.

----------

## swalker

I had the same problem.  

/etc/env.d/tomcat tries to set JAVA_HOME.  But /etc/env.d/20java should already be setting JAVA_HOME.  Not sure why the tomcat ebuild wants to set JAVA_HOME again.  Commenting out JAVA_HOME in the /etc/env.d/tomcat worked for me.

```
# $Header: /home/cvsroot/gentoo-x86/net-www/tomcat/files/4.1.24/tomcat.conf,v 1.2 2003/03/28 07:39:03 absinthe Exp $

                                                                                

# JVM Runtime

# Using the default setting, it will determine your JVM from the system-vm

# set using java-config.

# See java-config(1) manual page for assistance in determining this value.

#

# You can override this value with whatever path you wish.

# Example: JAVA_HOME=/opt/sun-jdk-1.4.1.01

                                                                                

#JAVA_HOME=`/bin/grep -e "JAVA_HOME" /etc/profile.env | /bin/sed -e "s/^.*'\(.*\)'$/\1/"`

                                                                                

# (Optional) Java runtime options used when the "start", "stop", or "run"

# commands are executed.

# JAVA_OPTS=""

```

----------

## absinthe

Folks ...

This is covered in the Gentoo Java Guide.  You need to have your default system vm set by using 'java-config' as indicated in the document.

Don't try to second-guess the configuration files unless you want to do it manually and if that's your choice, you're on your own.

If you follow the instructions, and set your default system VM after you install the JDK/JRE, the tomcat/jboss defaults will work just fine.

----------

## swalker

 *Quote:*   

> 
> 
> If you follow the instructions, and set your default system VM after you install the JDK/JRE, the tomcat/jboss defaults will work just fine.
> 
> 

 

Actually it behaves differently on bootup.

env-update seems to call some python module.  

```

x24 init.d # more /usr/sbin/env-update

#!/usr/bin/python2.2

# Copyright 1999-2003 Gentoo Technologies, Inc.

# Distributed under the terms of the GNU General Public License v2

# $Header: /home/cvsroot/gentoo-src/portage/bin/env-update,v 1.5 2003/02/22 16:59:08 carpaski Exp $

 

import portage

portage.env_update()

```

And /etc/init.d/bootmisc runs a shell script /sbin/rc-envupdate.sh

env-update will set JAVA_HOME correctly.  But running /sbin/rc-envupdate.sh ( which is what happens at boot ) does not.

```

x24 init.d # env-update

>>> Regenerating /etc/ld.so.cache...

x24 init.d # cat /etc/profile.env | grep JAVA_HOME

export JAVA_HOME='/opt/blackdown-jdk-1.3.1'

x24 init.d # /sbin/rc-envupdate.sh

x24 init.d # cat /etc/profile.env | grep JAVA_HOME

export JAVA_HOME=''

x24 init.d #

```

Again I commented out the JAVA_HOME in /etc/env.d/tomcat.  It seems unnecessary to me, and doesn't work on bootup.

----------

## absinthe

 *swalker wrote:*   

> 
> 
> Again I commented out the JAVA_HOME in /etc/env.d/tomcat.  It seems unnecessary to me, and doesn't work on bootup.

 

OK... there are a couple of things on our end that are minor but only one of them might be affecting you.

 There was a minor defect in the 4.1.24 ebuild which was not copying the right file into env.d, but this would not have stopped your system from running tomcat properly at boot-up.

There isn't a RDEPEND for sed, which is needed for the startup script.

Both have since been corrected.  The missing RDEPEND for sed was a complete oversight on my part.  

This new information sets up one of three possible scenarios:

If sed is installed, and the Java system-vm set up correctly:  Tomcat will start as expected.

If you don't have sys-apps/sed installed, the defaults in /etc/conf.d/tomcat would fail on startup because it can't find the sed binary.  Solution:  emerge sed, or follow the steps given below.

If you don't have your Java system-vm set up, the defaults in /etc/conf.d/tomcat will not get set up correctly because it can't find JAVA_HOME in /etc/profile.env.  Solution:  Read the Gentoo Java Guide.

I suggest doing the following to ensure that the defaults will work correctly and that your environment is sane:

# unmerge tomcat 

# rm /etc/conf.d/tomcat

Follow the instructions in the Gentoo Java Guide, and set your system-vm.

# emerge sync (to pull the updated 4.1.24 ebuild)

# emerge tomcat

If you follow those steps, it should work out of the box by running /etc/init.d/tomcat start.

Cheers

----------

## swalker

 *Quote:*   

> 
> 
>  There was a minor defect in the 4.1.24 ebuild which was not copying the right file into env.d, but this would not have stopped your system from running tomcat properly at boot-up. 
> 
> 

 

This is the problem, and it does cause tomcat not to start correctly after a reboot.  

 *Quote:*   

> 
> 
> # # unmerge tomcat
> 
> # # rm /etc/conf.d/tomcat
> ...

 

You also need to remove /etc/env.d/tomcat since this is the file that shouldn't be there.  ( If unmerging tomcat didn't remove it )

```

rm /etc/env.d/tomcat

```

fwiw - I've had sed installed.  And my java environment has always been setup correctly.

```

x24 root # which sed

/bin/sed

x24 root # java-config --list-available-vms

 [blackdown-jdk-1.3.1] Blackdown JDK 1.3.1 (/etc/env.d/java/20blackdown-jdk-1.3.1) (*)

 [blackdown-jdk-1.4.1] Blackdown JDK 1.4.1 (/etc/env.d/java/20blackdown-jdk-1.4.1) ()

x24 root #

```

Following the instructions above, plus removing /etc/env.d/tomcat - tomcat now works correctly.

Thanks for the ebuild, and for fixing it so quickly.

----------

## psiXaos

oh man thanks. that was my source of pain for 2 hours until I've decided to look at the gentoo forums at last! STFF!

----------

## Fillzee

I believe that

```

x24 root # java-config --list-available-vms

[blackdown-jdk-1.3.1] Blackdown JDK 1.3.1 (/etc/env.d/java/20blackdown-jdk-1.3.1) (*)

[blackdown-jdk-1.4.1] Blackdown JDK 1.4.1 (/etc/env.d/java/20blackdown-jdk-1.4.1) ()

x24 root #
```

isn't whats important. The output of 

```
java-config --jdk-home
```

is what should tell you where the currently selected java virtual machine is. You can have multiple java vms's installed but if one of them isn't set using something like 

```
java-config --set-system-vm=blackdown-jdk-1.4.1 
```

 it won't matter how many javas are listed using the --list-available-vms switch.

----------

## absinthe

 *Fillzee wrote:*   

> I believe that
> 
> ```
> 
> x24 root # java-config --list-available-vms
> ...

 

Actually, you're wrong.  How do you you think jdk-home gets set?  By default, after your first JDK gets installed, there is no system-vm configured.  The user has to run java-config to make this setting.

So when I ask people to do this, I am making sure it has been done.  Because otherwise, JAVA_HOME will not be available.

You have to start at the first link in the chain when troubleshooting.

----------

## Fillzee

Isn't that what I said? I'm not trying to be a smart ass, just trying to clarify for myself and everyone else. What I ment is that if you don't set the system wide vm, JAVA_HOME won't be set to anything and everything java will complain. I thought thats what the 

```
java-config --set-system-vm
```

 command was for. THe 

```
java-config --list-available-vms
```

 just tells you what it can be set to. I'm not shure if this gets set by default to the first vm that is installed ( I did that a long time ago ) but I know that someware along the line I had it set to nothing and everything java complained since it didn't know where tha java interpreter was anymore.

----------

