Return-Path:
Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm
Delivered-To: mailing list tomcat-dev@jakarta.apache.org
Received: (qmail 8555 invoked by uid 500); 16 Mar 2000 20:43:27 -0000
Delivered-To: apmail-jakarta-tomcat-cvs@apache.org
Received: (qmail 8552 invoked by uid 1052); 16 Mar 2000 20:43:27 -0000
Date: 16 Mar 2000 20:43:27 -0000
Message-ID: <20000316204327.8551.qmail@locus.apache.org>
From: costin@locus.apache.org
To: jakarta-tomcat-cvs@apache.org
Subject: cvs commit: jakarta-tomcat/src/shell tomcat.sh
costin 00/03/16 12:43:27
Modified: src/doc/uguide tomcat_ug.html
src/etc server.xml
src/share/org/apache/tomcat/context AutoSetup.java
DefaultCMSetter.java WebXmlReader.java
src/share/org/apache/tomcat/core Context.java
ContextManager.java
src/share/org/apache/tomcat/servlets DefaultServlet.java
src/share/org/apache/tomcat/startup Tomcat.java
src/share/org/apache/tomcat/util FileUtil.java
src/shell tomcat.sh
Log:
- Fix bug 49 - config file can be relative to the WD.
- Tomcat no longer requires a cd to tomcat.home
- consistent treatement of directories - all are relative to
context manager home, as defined in server.xml.
- reviewd check for absolute path
- documentBase is no longer used in tomcat.core, it is still there for
bkwd compatibility ( will be removed in 3.2 )
Revision Changes Path
1.2 +40 -13 jakarta-tomcat/src/doc/uguide/tomcat_ug.html
Index: tomcat_ug.html
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/doc/uguide/tomcat_ug.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- tomcat_ug.html 2000/03/16 12:19:56 1.1
+++ tomcat_ug.html 2000/03/16 20:43:22 1.2
@@ -1,11 +1,12 @@
-
+
Tomcat - A Minimalistic Users Guid
+
@@ -222,7 +223,7 @@
development team provides a few scripts to ease starting and stopping
Tomcat
-
Note: The scripts or only a convenient way to start/stop...
+
Note: The scripts are only a convenient way to start/stop...
You can modify them to customize the CLASSPATH, environment variables
such as PATH and LD_LIBRARY_PATH, etc. as long as you generate a
correct command line for Tomcat.
@@ -236,19 +237,19 @@
Description
-
startup
-
Starts tomcat in the background
-
-
-
shutdown
-
Stops tomcat (shutting it down)
-
-
tomcat
The main script. Set the proper environment (including
CLASSPATH, TOMCAT_HOME and JAVA_HOME) and start Tomcat with the
proper command line parameters.
+
+
startup
+
Starts tomcat in the background. Shortcut for "tomcat start"
+
+
+
shutdown
+
Stops tomcat (shutting it down). Shortcut for "tomcat stop"
+
The script whose behavior is the most important for us is
@@ -392,8 +393,10 @@
The ContextManager has a few attributes that provides it with:
Debug level used for logging debug messages.
-
The location of the home directory (relative to the TOMCAT_HOME)
-
The name of the temporary working directory.
+
The base location for webapps/, conf/, logs/ and all defined contexts.
+ It is used to start tomcat from directory different from TOMCAT_HOME.
+
+
The name of the working directory.
@@ -445,7 +448,25 @@
-
+
+
Starting tomcat from another directory
+
+
By default tomcat will use TOMCAT_HOME/conf/server.xml for configuration. The default
+ configuration will use TOMCAT_HOME as base for the contexts.
+
You can change this by using "-f /path/to/server.xml" option, and a different server
+ configuration file and setting the home property of the context manger. You need to
+ set up the required files inside the home:
+
+
A webapps/ directory ( if you create one ) - all war files will be expanded and
+ all subdirectories added as contexts.
+
conf/ directory - you can store a special web.xml and other configuration files
+
logs/ - all logs will go to this directory instead of the main TOMCAT_HOME/logs/
+
work/ - work directories for the contexts.
+
+
+
+
If the ContextManager.home property in server.xml is relative, it will be relative to
+ the current working directory.
web.xml
@@ -536,6 +557,12 @@
it tries to provide a better insight of the configuration instructions. You can find
additional information the
jserv install page .
+
+
+
When Tomcat starts up it will automatically generate a configuration file for
+ Apache in TOMCAT_HOME/conf/tomcat-apache.conf Most of the time you don't need to
+ do anything but include this file ( using Include ) in your httpd.conf.
+ If you have special needs, you can use this file as a base for your customized configuration.
The Apache-Tomcat configuration uses Apache core configuration directives
1.13 +6 -1 jakarta-tomcat/src/etc/server.xml
Index: server.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- server.xml 2000/02/24 23:01:25 1.12
+++ server.xml 2000/03/16 20:43:22 1.13
@@ -31,7 +31,12 @@
path="logs/jasper.log"
verbosityLevel = "INFORMATION" />
-
+
+
1.8 +5 -2 jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java
Index: AutoSetup.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/AutoSetup.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AutoSetup.java 2000/02/22 21:06:36 1.7
+++ AutoSetup.java 2000/03/16 20:43:22 1.8
@@ -135,8 +135,11 @@
Context ctx=new Context();
ctx.setContextManager( cm );
ctx.setPath(path);
- ctx.setDocBase( "webapps/" + name);
- if( debug > 0) ctx.log("");
+ // use absolute filename based on CM home instead of relative
+ // don't assume HOME==TOMCAT_HOME
+ File f=new File( webappD, name);
+ ctx.setDocBase( f.getAbsolutePath() );
+ if( debug > 0) ctx.log("");
cm.addContext(ctx);
} else {
//System.out.println("Already set up: " + path + " " + cm.getContext(path));
1.25 +3 -3 jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java
Index: DefaultCMSetter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/DefaultCMSetter.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- DefaultCMSetter.java 2000/03/15 14:51:39 1.24
+++ DefaultCMSetter.java 2000/03/16 20:43:22 1.25
@@ -82,10 +82,10 @@
}
public void engineInit(ContextManager cm) throws TomcatException {
- // check if we are in the right directory
- File f=new File( cm.getHome() + "/conf/web.xml");
+ // check if we have the right tomcat home directory
+ File f=new File( cm.getTomcatHome() + "/conf/web.xml");
if( ! f.exists() ) {
- throw new TomcatException( "Wrong home " + cm.getHome());
+ throw new TomcatException( "Wrong tomcat home " + cm.getHome());
}
}
1.16 +21 -6 jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java
Index: WebXmlReader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/context/WebXmlReader.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- WebXmlReader.java 2000/03/01 07:51:53 1.15
+++ WebXmlReader.java 2000/03/16 20:43:23 1.16
@@ -25,16 +25,31 @@
public WebXmlReader() {
}
- public void contextInit(Context ctx) {
+ public void contextInit(Context ctx) throws TomcatException {
if( ctx.getDebug() > 0 ) ctx.log("XmlReader - init " + ctx.getPath() + " " + ctx.getDocBase() );
// read default web.xml
try {
String home = ctx.getContextManager().getHome();
- processFile(ctx, home + "/conf/web.xml");
- File inf_xml = new File(ctx.getDocBase() + "/WEB-INF/web.xml");
- if (!inf_xml.isAbsolute())
- inf_xml = new File(home, inf_xml.toString());
+ // XXX make it configurable
+ File default_xml=new File( home + "/conf/web.xml" );
+
+ // try the default ( installation )
+ if( ! default_xml.exists() ) {
+ String tchome=ctx.getContextManager().getTomcatHome();
+ if( tchome != null )
+ default_xml=new File( tchome + "/conf/web.xml");
+ }
+
+ if( ! default_xml.exists() )
+ throw new TomcatException("Can't find default web.xml configuration");
+
+ processFile(ctx, default_xml.toString());
+ File inf_xml = new File(ctx.getDocBase() + "/WEB-INF/web.xml");
+ // if relative, base it to cm.home
+ if (!inf_xml.isAbsolute())
+ inf_xml = new File(home, inf_xml.toString());
+
processFile(ctx, inf_xml.toString());
XmlMapper xh=new XmlMapper();
} catch (Exception e) {
@@ -48,7 +63,7 @@
try {
File f=new File(FileUtil.patch(file));
if( ! f.exists() ) {
- ctx.log( "File not found, using defaults " + f );
+ ctx.log( "File not found " + f + ", using only defaults" );
return;
}
if( ctx.getDebug() > 0 ) ctx.log("Reading " + file );
1.68 +29 -19 jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Context.java,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -r1.67 -r1.68
--- Context.java 2000/03/08 00:25:11 1.67
+++ Context.java 2000/03/16 20:43:23 1.68
@@ -188,13 +188,15 @@
* and set up War interceptors.
*
* "Basic" tomcat treats it is a file ( either absolute or relative to
- * the CM home ). XXX Make it absolute ??
+ * the CM home ).
*
+ * If docBase is relative assume it is relative to the context manager home.
*/
public void setDocBase( String docB ) {
this.docBase=docB;
}
+
public String getDocBase() {
return docBase;
}
@@ -635,8 +637,20 @@
public URL getResource(String rpath) throws MalformedURLException {
URL url = null;
+ String absPath=getDocBase();
+
+ if (FileUtil.isAbsolute( docBase ) )
+ absPath=docBase;
+ else
+ absPath = contextM.getHome() + File.separator + docBase;
+
+ try {
+ absPath = new File(absPath).getCanonicalPath();
+ } catch (IOException npe) {
+ }
+
if ("".equals(rpath))
- return getDocumentBase();
+ return new URL( "file", null, 0, absPath );
if (rpath == null)
return null;
@@ -659,7 +673,6 @@
if(mappedPath == null )
mappedPath=lr.getLookupPath();
- URL documentBase = getDocumentBase();
try {
String contextHome=new File( docBase ).getCanonicalPath();
String realPath=contextHome + mappedPath;
@@ -671,9 +684,9 @@
// in order to support non-file based repositories.
return null;
}
- url=new URL(documentBase.getProtocol(), documentBase.getHost(),
- documentBase.getPort(),
- documentBase.getFile() + mappedPath);
+ url=new URL("file", null,
+ 0,
+ absPath + mappedPath);
if( debug>9) log( "getResourceURL=" + url + " request=" + lr );
return url;
} catch( IOException ex ) {
@@ -706,7 +719,9 @@
// Real Path is the same as PathTranslated for a new request
Context base=this; // contextM.getContext("");
- Request req=contextM.createRequest( base , FileUtil.normPath(path) );
+ String normP=FileUtil.normPath(path);
+
+ Request req=contextM.createRequest( base , normP );
contextM.processRequest(req);
String mappedPath = req.getMappedPath();
@@ -719,13 +734,13 @@
String realPath= this.getDocBase() + mappedPath;
- // evaluate relative paths relative to the context's home
- if (!(new File(realPath).isAbsolute()))
- realPath = contextM.getHome() + "/" + realPath;
+ if (!(new File(realPath).isAbsolute()))
+ realPath = contextM.getHome() + "/" + realPath;
// Probably not needed - it will be used on the local FS
realPath = FileUtil.patch(realPath);
+ if( debug>5) log("Get real path " + path + " " + realPath + " " + normP );
return realPath;
}
@@ -897,6 +912,7 @@
}
/** @deprecated - use getDocBase and URLUtil if you need it as URL
+ * NOT USED INSIDE TOMCAT - ONLY IN OLD J2EE CONNECTORS !
*/
public URL getDocumentBase() {
if( documentBase == null ) {
@@ -905,17 +921,11 @@
try {
String absPath=docBase;
- // detect absolute path
- if (docBase.startsWith(File.separator) ||
- docBase.startsWith("/") ||
- ( docBase.length() >= 2 &&
- Character.isLetter(docBase.charAt(0)) &&
- docBase.charAt(1) == ':')
- ) {
+ // detect absolute path ( use the same logic in all tomcat )
+ if (FileUtil.isAbsolute( docBase ) )
absPath=docBase;
- } else {
+ else
absPath = contextM.getHome() + File.separator + docBase;
- }
try {
absPath = new File(absPath).getCanonicalPath();
1.59 +26 -7 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- ContextManager.java 2000/03/03 22:30:23 1.58
+++ ContextManager.java 2000/03/16 20:43:24 1.59
@@ -420,27 +420,46 @@
/** The root directory of tomcat
*/
public String getHome() {
- if( home == null ) setHome(".");
+ if(home!=null) return home;
+
+ // If none defined, assume tomcat.home is used as base.
+ String homeS=System.getProperty("tomcat.home");
+ if( homeS != null )
+ setHome( homeS );
+ else
+ setHome("."); // try current dir - we should throw an exception
return home;
}
+ /** Tomcat installation directory, where libraries and default files are located
+ */
+ public String getTomcatHome() {
+ return System.getProperty("tomcat.home");
+ }
+
/**
- * Set installation directory. If path specified is relative, evaluate
- * it relative to the tomcat.home property if available, otherwise,
+ * Set installation directory. If path specified is relative,
* evaluate it relative to the current working directory.
+ *
+ * This is used for the home attribute and it's used to find webapps
+ * and conf. Note that libs are probably already configured, so it will
+ * not affect that.
*/
public void setHome(String home) {
File homeFile = new File(home);
- if (!homeFile.isAbsolute()) {
- String tomcat_home = System.getProperty("tomcat.home");
- if (tomcat_home != null) homeFile = new File(tomcat_home, home);
- }
+
+ // change it if you want relative home based on tomcat.home
+ // if (!homeFile.isAbsolute()) {
+ // String tomcat_home = System.getProperty("tomcat.home");
+ // if (tomcat_home != null) homeFile = new File(tomcat_home, home);
+ // }
try {
this.home = homeFile.getCanonicalPath();
} catch (IOException ioe) {
this.home = home; // oh well, we tried...
}
+ log( "Setting home to " + this.home );
}
/**
1.9 +4 -4 jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultServlet.java
Index: DefaultServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/servlets/DefaultServlet.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DefaultServlet.java 2000/02/27 03:23:35 1.8
+++ DefaultServlet.java 2000/03/16 20:43:24 1.9
@@ -86,16 +86,16 @@
public void init() throws ServletException {
contextF = getServletContext();
context = ((ServletContextFacade)getServletContext()).getRealContext();
-
+
// doesn't change - set it in init!
docBase = context.getDocBase();
if (! docBase.endsWith("/")) {
docBase += "/";
}
- // ensure docBase relative to home
- if (!(new File(docBase)).isAbsolute())
- docBase = context.getContextManager().getHome() + "/" + docBase;
+ // ensure docBase relative to home
+ if (!(new File(docBase)).isAbsolute())
+ docBase = context.getContextManager().getHome() + "/" + docBase;
// debug
String dbg=getServletConfig().getInitParameter("debug");
1.17 +24 -2 jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
Index: Tomcat.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Tomcat.java 2000/03/01 01:26:20 1.16
+++ Tomcat.java 2000/03/16 20:43:25 1.17
@@ -104,7 +104,26 @@
setConnectorHelper( xh );
setLogHelper( xh );
- File f=new File(cm.getHome(), configFile);
+ File f;
+
+ // - if no -f config is specified, use tomcat.home and set ContextManager.home to the same thing.
+ // The user probably wants the default tomcat.
+ // - if a config file is specified - just use it, it will probably set the contextmanager home.
+ if( configFile==null ) {
+ String tchome=System.getProperty("tomcat.home");
+ if( tchome == null ) {
+ System.out.println("No tomcat.home property, you need to set TOMCAT_HOME or add -Dtomcat.home ");
+ // try "." - a better solution would be to just exit.
+ tchome=".";
+ }
+ // Home will be identical to tomcat home if default config is used.
+ cm.setHome( tchome );
+ f=new File(tchome, DEFAULT_CONFIG );
+ } else {
+ // config file is relative to the working directory
+ // if it doesn't set a home for the context manager, tomcat.home will be used
+ f=new File(configFile);
+ }
try {
xh.readXml(f,cm);
@@ -188,7 +207,10 @@
}
// -------------------- Command-line args processing --------------------
- String configFile="conf/server.xml";
+ // null means user didn't set one
+ String configFile=null;
+ // relative to TOMCAT_HOME
+ static final String DEFAULT_CONFIG="conf/server.xml";
boolean doStop=false;
public static void printUsage() {
1.5 +16 -3 jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java
Index: FileUtil.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FileUtil.java 2000/02/08 23:52:49 1.4
+++ FileUtil.java 2000/03/16 20:43:26 1.5
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v 1.4 2000/02/08 23:52:49 costin Exp $
- * $Revision: 1.4 $
- * $Date: 2000/02/08 23:52:49 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/FileUtil.java,v 1.5 2000/03/16 20:43:26 costin Exp $
+ * $Revision: 1.5 $
+ * $Date: 2000/03/16 20:43:26 $
*
* ====================================================================
*
@@ -166,6 +166,19 @@
return patchPath;
}
+ public static boolean isAbsolute( String path ) {
+ // normal file
+ if( path.startsWith("/" ) ) return true;
+
+ if( path.startsWith(File.separator ) ) return true;
+
+ // win c:
+ if (path.length() >= 3 &&
+ Character.isLetter(path.charAt(0)) &&
+ path.charAt(1) == ':')
+ return true;
+ return false;
+ }
// Probably not needed, original code used by Context.getRealPath()
// XXX Find if it is duplicated, merge with the other "path" functions
1.15 +10 -17 jakarta-tomcat/src/shell/tomcat.sh
Index: tomcat.sh
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/shell/tomcat.sh,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- tomcat.sh 2000/03/01 20:32:48 1.14
+++ tomcat.sh 2000/03/16 20:43:26 1.15
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $Id: tomcat.sh,v 1.14 2000/03/01 20:32:48 costin Exp $
+# $Id: tomcat.sh,v 1.15 2000/03/16 20:43:26 costin Exp $
# Shell script to start and stop the server
@@ -60,13 +60,14 @@
exit 1
fi
+
if [ -z "$JAVA_HOME" ] ; then
- JAVACMD=`which java`
- if [ -z "$JAVACMD" ] ; then
+ JAVA=`which java`
+ if [ -z "$JAVA" ] ; then
echo "Cannot find JAVA. Please set your PATH."
exit 1
fi
- JAVA_BINDIR=`dirname $JAVACMD`
+ JAVA_BINDIR=`dirname $JAVA`
JAVA_HOME=$JAVA_BINDIR/..
fi
@@ -82,9 +83,11 @@
for i in ${TOMCAT_HOME}/lib/* ; do
CLASSPATH=${CLASSPATH}:$i
done
-
-CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
+if [ -f ${JAVA_HOME}/lib/tools.jar ] ; then
+ # We are probably in a JDK1.2 environment
+ CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
+fi
# Backdoor classpath setting for development purposes when all classes
# are compiled into a /classes dir and are not yet jarred.
@@ -98,23 +101,13 @@
export CLASSPATH
-if [ ! -f conf/server.xml ] ; then
- if [ "$2" = "" ] ; then
- # Probably we are in a wrong directory, use tomcat_home
- # If arguments are passed besides start/stop, probably a -f was used,
- # or the user knows what he's doing
- echo cd ${TOMCAT_HOME}
- cd ${TOMCAT_HOME}
- fi
-fi
-
# We start the server up in the background for a couple of reasons:
# 1) It frees up your command window
# 2) You should use `stop` option instead of ^C to bring down the server
if [ "$1" = "start" ] ; then
shift
echo Using classpath: ${CLASSPATH}
- $JAVACMD -Dtomcat.home=${TOMCAT_HOME} org.apache.tomcat.startup.Tomcat "$@" &
+ $JAVACMD -Dtomcat.home=${TOMCAT_HOME} org.apache.tomcat.startup.Tomcat "$@" &
# $JAVACMD org.apache.tomcat.shell.Startup "$@" &
elif [ "$1" = "stop" ] ; then