You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by GOMEZ Henri <hg...@slib.fr> on 2002/02/15 11:23:04 UTC

Java home autodiscovery add-on

What about adding this part in tomcat.sh (TC 3.3) and
catalina.sh/jasper.sh to help them discover JAVA_HOME on 
at least Linux systems ?

+if [ -z "$JAVA_HOME" ]; then
+    # Search for java in PATH
+    JAVA=`which java`
+    if [ -z "$JAVA" ] ; then
+    JAVA_BINDIR=`dirname ${JAVA}`
+    JAVA_HOME="${JAVA_BINDIR}/.."
+    fi
+    # Default clean JAVA_HOME
+    [ -z "$JAVA_HOME"  -a -d "/usr/lib/java" ] &&  JAVA_HOME="/usr/lib/java"
+    # Default IBM JAVA_HOME
+    [ -z "$JAVA_HOME"  -a -d "/opt/IBMJava2-13" ] &&  JAVA_HOME="/opt/IBMJava2-13"
+    # Another solution
+    [ -z "$JAVA_HOME"  -a -d "/usr/java/jdk" ] &&  JAVA_HOME="/usr/java/jdk"
+    # madeinlinux JAVA_HOME
+    [ -z "$JAVA_HOME" -a -d "/usr/local/jdk1.2.2" ] && JAVA_HOME="/usr/local/jdk1.2.2"
+    # Kondara JAVA_HOME
+    [ -z "$JAVA_HOME"  -a -d "/usr/lib/java/jdk1.2.2" ] && JAVA_HOME="/usr/lib/java/jdk1.2.2"
+    # Other commonly found JAVA_HOMEs
+    [ -z "$JAVA_HOME"  -a -d "/usr/jdk1.2" ] && JAVA_HOME="/usr/jdk1.2"
+    # Default Caldera JAVA_HOME
+    [ -z "$JAVA_HOME"  -a -d "/opt/java-1.3" ] && JAVA_HOME="/opt/java-1.3"
+    # Add other locations here
+    if [ -z "$JAVA_HOME" ]; then
+        echo "No JAVA_HOME specified in ${TOMCAT_CFG} and no java found, exiting..."
+        exit 1
+  fi

the ${TOMCAT_CFG} is a config file (shell) which allow you to setup 
TC 3.3/4.0.2 runtime, and could be also added to CVS :

=> TC 3.3 conf :

# tomcat /etc/rc.d script example configuration file
# Use with version 1.07 of the scripts or later

# Where your java installation lives
# JAVA_HOME=/usr/java/jdk
JAVA_HOME="/opt/IBMJava2-13"

# You can pass some parameters to java
# here if you wish to
#JAVACMD="$JAVA_HOME/bin/java -Xminf0.1 -Xmaxf0.3"

# Where your tomcat installation lives
# That change from previous RPM where TOMCAT_HOME 
# used to be /var/tomcat.
# Now /var/tomcat will be the base for webapps only
TOMCAT_HOME="@@@TCHOME@@@"

# Where our webapps/libs are now installed.
TOMCAT_INSTALL="@@@TCINST@@@"

# What user should run tomcat
TOMCAT_USER="tomcat3"

# You can change your tomcat locale here
#LANG=en_US

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
# Just do not forget to export them :)


=> TC 4.0.2 conf :

# tomcat /etc/rc.d script example configuration file
# Use with version 1.07 of the scripts or later

# Where your java installation lives
# JAVA_HOME=/usr/java/jdk
JAVA_HOME="/opt/IBMJava2-13"

# You can pass some parameters to java
# here if you wish to
#JAVACMD="$JAVA_HOME/bin/java -Xminf0.1 -Xmaxf0.3"

# Where your tomcat installation lives
# That change from previous RPM where TOMCAT_HOME 
# used to be /var/tomcat.
# Now /var/tomcat will be the base for webapps only
CATALINA_HOME="@@@TCHOME@@@"
JASPER_HOME="@@@TCHOME@@@"
CATALINA_TMPDIR="@@@TCHOME@@@/temp"

# What user should run tomcat
TOMCAT_USER="tomcat4"

# You can change your tomcat locale here
#LANG=en_US

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
# Just do not forget to export them :)


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Java home autodiscovery add-on

Posted by "Christopher K. St. John" <ck...@distributopia.com>.
GOMEZ Henri wrote:
> 
> What about adding this part in tomcat.sh (TC 3.3) and
> catalina.sh/jasper.sh to help them discover JAVA_HOME on
> at least Linux systems ?
> 

 If someone forgets to set JAVA_HOME and has multiple JDK's
installed, they could get a suprise. I suspect most non-beginners
would rather see an error message than be suprised. I ran into
this problem with a configure script that tried to be too smart
about finding a JDK to use.

-- 
Christopher St. John cks@distributopia.com
DistribuTopia http://www.distributopia.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Java home autodiscovery add-on

Posted by Patrick Luby <pa...@sun.com>.
Henri,

GOMEZ Henri wrote:
> 
> What about adding this part in tomcat.sh (TC 3.3) and
> catalina.sh/jasper.sh to help them discover JAVA_HOME on
> at least Linux systems ?
> 
> +if [ -z "$JAVA_HOME" ]; then
> +    # Search for java in PATH
> +    JAVA=`which java`
> +    if [ -z "$JAVA" ] ; then
> +    JAVA_BINDIR=`dirname ${JAVA}`
> +    JAVA_HOME="${JAVA_BINDIR}/.."
> +    fi
> +    # Default clean JAVA_HOME
> +    [ -z "$JAVA_HOME"  -a -d "/usr/lib/java" ] &&  JAVA_HOME="/usr/lib/java"
> +    # Default IBM JAVA_HOME
> +    [ -z "$JAVA_HOME"  -a -d "/opt/IBMJava2-13" ] &&  JAVA_HOME="/opt/IBMJava2-13"
> +    # Another solution
> +    [ -z "$JAVA_HOME"  -a -d "/usr/java/jdk" ] &&  JAVA_HOME="/usr/java/jdk"
> +    # madeinlinux JAVA_HOME
> +    [ -z "$JAVA_HOME" -a -d "/usr/local/jdk1.2.2" ] && JAVA_HOME="/usr/local/jdk1.2.2"
> +    # Kondara JAVA_HOME
> +    [ -z "$JAVA_HOME"  -a -d "/usr/lib/java/jdk1.2.2" ] && JAVA_HOME="/usr/lib/java/jdk1.2.2"
> +    # Other commonly found JAVA_HOMEs
> +    [ -z "$JAVA_HOME"  -a -d "/usr/jdk1.2" ] && JAVA_HOME="/usr/jdk1.2"
> +    # Default Caldera JAVA_HOME
> +    [ -z "$JAVA_HOME"  -a -d "/opt/java-1.3" ] && JAVA_HOME="/opt/java-1.3"
> +    # Add other locations here
> +    if [ -z "$JAVA_HOME" ]; then
> +        echo "No JAVA_HOME specified in ${TOMCAT_CFG} and no java found, exiting..."
> +        exit 1
> +  fi
>

In Tomcat 4.0.2 and later, the above code would, I believe, fit into the
bin/setclasspath.sh script. This script, which already checks that your
$JAVA_HOME contains a java, javac, and jdb command, would extend that
functionality. BTW, setclasspath.sh is source by all the executable Unix scripts
(e.g. catalina.sh, jasper.sh, etc.).

Something that the Tomcat 3.3 developers may want to take a look at in
setclasspath.sh is the setting of $JAVA_ENDORSED_DIRS environment variable. This
variable is used to construct a "-Djava.endorsed.dirs=<xxxx>" argument when
invoking Java in each of teh executable Unix scripts (Windows does the same in
setclasspath.bat). This property provides the ability for Tomcat to override the
default parser and other special classes that are bundled with JDK 1.4 with the
classes that are bundled with Tomcat. This eliminates the need for users to need
to copy jar files into their JDK's lib/endorsed directory (which would affect
all other Java applications).
 
> 
> => TC 4.0.2 conf :
> 
> # tomcat /etc/rc.d script example configuration file
> # Use with version 1.07 of the scripts or later
> 
> # Where your java installation lives
> # JAVA_HOME=/usr/java/jdk
> JAVA_HOME="/opt/IBMJava2-13"
> 
> # You can pass some parameters to java
> # here if you wish to
> #JAVACMD="$JAVA_HOME/bin/java -Xminf0.1 -Xmaxf0.3"
> 
> # Where your tomcat installation lives
> # That change from previous RPM where TOMCAT_HOME
> # used to be /var/tomcat.
> # Now /var/tomcat will be the base for webapps only
> CATALINA_HOME="@@@TCHOME@@@"
> JASPER_HOME="@@@TCHOME@@@"
> CATALINA_TMPDIR="@@@TCHOME@@@/temp"
> 
> # What user should run tomcat
> TOMCAT_USER="tomcat4"
> 
> # You can change your tomcat locale here
> #LANG=en_US
> 
> # If you wish to further customize your tomcat environment,
> # put your own definitions here
> # (i.e. LD_LIBRARY_PATH for some jdbc drivers)
> # Just do not forget to export them :)
>

Many may not know this, but the above configuration file already exists in
Tomcat 4.0.2 and later. The configuration files are:

   Windows:  bin/setenv.bat
   Unix:     bin/setenv.sh

These files, by default, do not exist. However, if the user creates the above
file, they can override any environment variables that they like.

Something that the Tomcat 3.3 developers may want to take a look at is that each
Unix script in Tomcat 4.0.2 and later now resolves CATALINA_HOME independently
of the user's environment. This even works if the user invokes a softlink to the
script (pretty handy if you want to put a softlink to startup.sh and shutdown.sh
in /usr/bin on your system). This, and putting "JAVA_HOME=<JDK path>" in the
setenv.sh file, allows you to run Tomcat 4.0.2 or later from an /etc/rc.d or
/etc/inittab entry.

I have found a way to do this on Windows NT, 2000, and XP, but I have not had
enough time to refine it enough so that it won't break Windows 95, 98, and ME.

Patrick

-- 
_____________________________________________________________________
Patrick Luby                          Email: patrick.luby@sun.com
Sun Microsystems                              Phone: 408-276-7471
901 San Antonio Road, USCA14-303
Palo Alto, CA 94303-4900
_____________________________________________________________________

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>