Setting the CLASSPATH

The sequence of the CLASSPATH entries is very important for successful deployment. TomCat has a batch file called tomcat.bat. This file is used by different TomCat tools to set the environment. In this file, TomCat always puts the .jar files that it needs in front of the .jar files you have specified in your CLASSPATH. You need to change this file to make TomCat add its .jar files after your .jar files. Here is a typical modified tomcat.bat file. Those places that we have changed are highlighted.

@echo off
rem -------------------------------------------------------------------------
rem tomcat.bat - Start/Stop Script for the TOMCAT Server
rem Environment Variable Prerequisites:
rem   TOMCAT_HOME  (Optional) May point at your Tomcat distribution
rem                directory.  If not present, the current working
rem                directory is assumed.
rem                Note: This batch file does not function properly
rem                if TOMCAT_HOME contains spaces.
rem   TOMCAT_OPTS  (Optional) Java runtime options used when the "start",
rem                "stop", or "run" command is executed
rem   CLASSPATH    (Optional) This batch file will automatically add
rem                what Tomcat needs to the CLASSPATH.  This consists
rem                of TOMCAT_HOME\classes and all the jar files in
rem                TOMCAT_HOME\lib. This will include the "jaxp.jar"
rem                and "parser.jar" files from the JAXP Reference
rem                implementation, and the "tools.jar" from the JDK.
rem   JAVA_HOME    Must point at your Java Development Kit installation.
rem $Id: tomcat.bat,v 2001/06/24 19:27:10 marcsaeg Exp $
rem -------------------------------------------------------------------------

rem ----- Save Environment Variables That May Change ------------------------

set _CP=%CP%

rem ----- Verify and Set Required Environment Variables ---------------------

if not "%JAVA_HOME%" == "" goto gotJavaHome
echo You must set JAVA_HOME to point at your Java Development Kit installation
goto cleanup

if not "%TOMCAT_HOME%" == "" goto gotTomcatHome
if exist "%TOMCAT_HOME%\lib\servlet.jar" goto okTomcatHome
echo Unable to locate servlet.jar, check the value of TOMCAT_HOME.
goto cleanup

rem ----- Prepare Appropriate Java Execution Commands -----------------------

if not "%OS%" == "Windows_NT" goto noTitle
set _SECSTARTJAVA=start "Secure Tomcat 3.2" "%JAVA_HOME%\bin\java"
set _STARTJAVA=start "Tomcat 3.2" "%JAVA_HOME%\bin\java"
set _RUNJAVA="%JAVA_HOME%\bin\java"
goto setClasspath

set _SECSTARTJAVA=start "%JAVA_HOME%\bin\java"
set _STARTJAVA=start "%JAVA_HOME%\bin\java"
set _RUNJAVA="%JAVA_HOME%\bin\java"

rem ----- Set Up The Runtime Classpath --------------------------------------

set CP=%TOMCAT_HOME%\classes
rem set CP=%CP%;%CLASSPATH%

rem Try to determine if TOMCAT_HOME contains spaces
if exist %TOMCAT_HOME%\lib\servlet.jar goto dynClasspath
echo Your TOMCAT_HOME appears to contain spaces.
echo Unable to set CLASSPATH dynamically.
goto staticClasspath

for %%i in (%TOMCAT_HOME%\lib\*.*) do call %TOMCAT_HOME%\bin\cpappend.bat %%i
if not "%_LIBJARS%" == "" goto gotLibJars
echo Unable to set CLASSPATH dynamically.
if "%OS%" == "Windows_NT" goto staticClasspath
echo Note: To set the CLASSPATH dynamically on Win9x systems
echo       only DOS 8.3 names may be used in TOMCAT_HOME!
goto staticClasspath

echo Including all jars in %TOMCAT_HOME%\lib in your CLASSPATH.
rem Note: _LIBJARS already contains a leading semicolon
goto chkClasspath

echo Setting your CLASSPATH statically.
if exist "%TOMCAT_HOME%\lib\ant.jar" set CP=%CP%;%TOMCAT_HOME%\lib\ant.jar
if exist "%TOMCAT_HOME%\lib\jasper.jar" set CP=%CP%;%TOMCAT_HOME%\lib\jasper.jar
if exist "%TOMCAT_HOME%\lib\jaxp.jar" set CP=%CP%;%TOMCAT_HOME%\lib\jaxp.jar
if exist "%TOMCAT_HOME%\lib\parser.jar" set CP=%CP%;%TOMCAT_HOME%\lib\parser.jar
if exist "%TOMCAT_HOME%\lib\servlet.jar" set CP=%CP%;%TOMCAT_HOME%\lib\servlet.jar
if exist "%TOMCAT_HOME%\lib\webserver.jar" set CP=%CP%;%TOMCAT_HOME%\lib\webserver.jar

if "%CLASSPATH%" == "" goto noClasspath
if not exist "%JAVA_HOME%\lib\tools.jar" goto installClasspath
set CP=%CLASSPATH%;%CP%;%JAVA_HOME%\lib\tools.jar;
echo Using CLASSPATH: %CP%

rem ----- Execute The Requested Command -------------------------------------

if "%1" == "start" goto startServer
if "%1" == "stop" goto stopServer
if "%1" == "run" goto runServer
if "%1" == "ant" goto runAnt
if "%1" == "env" goto doEnv
if "%1" == "jspc" goto runJspc

echo Usage:  tomcat ( ant ^| env ^| jspc ^| run ^| start ^| stop )
echo Commands:
echo   ant -   Run Ant in Tomcat's environment
echo   env -   Set up environment variables that Tomcat would use
echo   jspc -  Run JSPC in Tomcat's environment
echo   run -   Start Tomcat in the current window
echo   start - Start Tomcat in a separate window
echo   stop -  Stop Tomcat
goto cleanup

goto finish

echo Starting Tomcat in new window
if "%2" == "-security" goto startSecure
%_STARTJAVA% %TOMCAT_OPTS% -Dtomcat.home="%TOMCAT_HOME%" org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup

echo Starting Tomcat with a SecurityManager
%_SECSTARTJAVA% %TOMCAT_OPTS%"%TOMCAT_HOME%/conf/tomcat.policy" -Dtomcat.home="%TOMCAT_HOME%" org.apache.tomcat.startup.Tomcat %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem Running Tomcat in this window
if "%2" == "-security" goto runSecure
%_RUNJAVA% %TOMCAT_OPTS% -Dtomcat.home="%TOMCAT_HOME%" org.apache.tomcat.startup.Tomcat %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem Running Tomcat with a SecurityManager
%_RUNJAVA% %TOMCAT_OPTS%"%TOMCAT_HOME%/conf/tomcat.policy" -Dtomcat.home="%TOMCAT_HOME%" org.apache.tomcat.startup.Tomcat %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem Stopping the Tomcat Server
%_RUNJAVA% %TOMCAT_OPTS% -Dtomcat.home="%TOMCAT_HOME%" org.apache.tomcat.startup.Tomcat -stop %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem Run ANT in Tomcat's Environment
set CP=%CP%;%TOMCAT_HOME%\lib\ant.jar
%_RUNJAVA% %ANT_OPTS% -Dant.home="%TOMCAT_HOME%" -Dtomcat.home="%TOMCAT_HOME%" %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem Run JSPC in Tomcat's Environment
%_RUNJAVA% %JSPC_OPTS% -Dtomcat.home="%TOMCAT_HOME%" org.apache.jasper.JspC %2 %3 %4 %5 %6 %7 %8 %9
goto cleanup

rem ----- Restore Environment Variables ---------------------------------------

set CP=%_CP%
set _CP=

Typical Batch File to Set the Environment Variables

You can set your PATH and CLASSPATH in a batch file and run this batch file before launching the TomCat server .Here is a typical batch file that can set the PATH and the CLASSPATH for you. We assume all .jar files we mentioned in the Library Files section are stored in D:\JLib.

PATH = C:\WINNT\system32;C:\WINNT;"C:\Program Files\Microsoft Visual Studio\VC98\Bin";D:\jdk1.3.1\bin;D:\jintegra\bin;
set TOMCAT_HOME=D:\jakarta-tomcat-3.2.3
set JAVA_HOME=D:\jdk1.3.1
set CLASSPATH=.;%JAVA_PATH%\xerces.jar;%JAVA_PATH%\xalan.jar;%JAVA_PATH%\jmxx.jar;
set CLASSPATH=%CLASSPATH%;%JAVA_PATH%\jmxc.jar;%JAVA_PATH%\bsf.jar;%JAVA_PATH%\js.jar;
set CLASSPATH=%CLASSPATH%;%JAVA_PATH%\axis.jar;%JAVA_PATH%\soap.jar;%JAVA_PATH%\xml4j.jar;
set CLASSPATH=%CLASSPATH%;%JAVA_PATH%\mail.jar;%JAVA_PATH%\activation.jar;%JAVA_PATH%\rt.jar;
set CLASSPATH=%JAVA_PATH%\uddi4j.jar;%JAVA_PATH%\log.jar;%JAVA_PATH%\logEnglish.jar;
set CLASSPATH=%CLASSPATH%;%JAVA_PATH%\jintegra.jar;%JAVA_PATH%\excel.jar;
set CLASSPATH=%CLASSPATH%;%JAVA_PATH%\excelwebservice.jar;

As you see in this typical batch file, we also set the PATH, and in this environment variable we include the path to the J-Integra® bin directory. In order to have access to a COM object, Windows needs to authenticate the caller. J-Integra® can perform the authentication on your behalf. To do that, J-Integra® needs to access some DLL files that are part of J-Integra® and are located in the bin directory. If you do not want to add this directory to your path, you must call AuthInfo.setDefault("Domain", "username", "password") in and provide the Windows NT domain name, user name, and password.