Bug 43578 - Tomcat fails to start on linux if CATALINA_HOME contains a space
Summary: Tomcat fails to start on linux if CATALINA_HOME contains a space
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: Nightly Build
Hardware: PC Linux
: P2 regression (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-09 07:35 UTC by Basil Revelas
Modified: 2008-08-27 13:51 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Basil Revelas 2007-10-09 07:35:47 UTC
I've managed to reproduce this on Fedora core 6 and Ubuntu Feisty using the
binary distribution tarballs of tomcat 6.0.14 and 5.5.25.

export JAVA_HOME=<path to java>
tar xzf <path to tarball>/apache-tomcat-*.tar.gz
mv apache-tomcat* "my tomcat directory"
bash "my tomcat directory/bin/catalina.sh" run

result:
Using CATALINA_BASE:   /home/basil/test/my tomcat directory
Using CATALINA_HOME:   /home/basil/test/my tomcat directory
Using CATALINA_TMPDIR: /home/basil/test/my tomcat directory/temp
Using JRE_HOME:       /usr/lib/jvm/java-6-sun
Exception in thread "main" java.lang.NoClassDefFoundError: tomcat

if "my tomcat directory" is replaced with, for example, "mytomcatdirectory",
tomcat starts with no error. This error will also occur if a parent directory
contains a space and CATALINA_HOME itself doesn't.
Comment 1 greg 2007-11-28 13:13:25 UTC
Same here on OSX, with 5.5.25 and 5.5.20. This was definitely working with 5.0.28.

This can not have been unnoticed for so long, right? What's going on? I'm sure it's been reported many 
times, but bugzilla being so user-friendly, I could hardly find anything...
Anyone knows if this was introduced in 5.5.2x or if it's there since 5.5.0 ?
Comment 2 greg 2007-11-28 13:16:03 UTC
Note that the exception is slightly different is your path only has one space (I get exactly the same 
behaviour, i.e NCDFE on the second "word" if several spaces)

$ ./startup.sh && tail -f ../logs/catalina.outUsing CATALINA_BASE:   /Applications/dev/test 
test2/apache-tomcat-5.5.25
Using CATALINA_HOME:   /Applications/dev/test test2/apache-tomcat-5.5.25
Using CATALINA_TMPDIR: /Applications/dev/test test2/apache-tomcat-5.5.25/temp
Using JRE_HOME:       /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home
Exception in thread "main" java.lang.NoClassDefFoundError: test2/apache-tomcat-
5/5/25/conf/logging/properties
^C

Comment 3 Ray Sauers 2007-11-29 04:53:05 UTC
I encountered a similar problem this morning, with CATALINA_BASE containing a space.

Here's what I have found:

1. The problem seems to be in the setting of JAVA_OPTS in the following:
# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
  JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-
Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi

If CATALINA_BASE has spaces, the shell splits JAVA_OPTS on the spaces when running the Java 
command line, causing the NCDFE.

2. I confirmed this by removing tomcat-juli.jar from bin, and tomcat started fine. This changed logging, 
so it wasn't a proper fix.

3. I was able to get things running, including logging, by making the following changes to catalina.sh

# Set juli LogManager if it is present
if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
  JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" 
  LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
fi

and then adding "$LOGGING_CONFIG" (note the quotes) to all places where JAVA_OPTS is passed to the 
java command line. For example:

      exec "$_RUNJDB" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \

I'm not sure if this is the best way to fix this, but it works by keeping the spaces inside CATALINA_BASE 
within quotes when passing the arguments to the java command line.

4. The problem exists in the latest 5.5 (5.5.25) and 6.0 (6.0.14), but not in 5.0.x.

Comment 4 Mark Thomas 2008-04-25 15:09:00 UTC
Thanks for the patch suggestion. This has been committed to trunk and proposed for 6.0.x and 5.5.x.
Comment 5 Mark Thomas 2008-05-01 12:05:20 UTC
This has been applied to 6.0.x and will be included in 6.0.17 onwards.
Comment 6 Peter Rossbach 2008-07-25 03:27:21 UTC
Hi,

I can't start tomcat with this patch at Mac OS X ( 10.4.11).

catalina.out
Exception in thread "main" java.lang.NoClassDefFoundError: 

#!/bin/bash
export CATALINA_HOME=/Users/peter/xxxx/apache-tomcat-6.0.18
export CATALINA_BASE=/Users/peter/xxxx/node01
exec $CATALINA_HOME/bin/catalina.sh start "$@"

The tomcat start fails as I set CATALINA_BASE to other directory then CATALINA_HOME. After I remove
quotes from $LOGGING_CONFIG at $CATALINA_HOME/bin/catalina.sh it works. Strange! I have no spaces at my paths and with 6.0.16 tomcat start perfect.

I think the LOGGING_CONFIG variable must also set at stop command at catalina.sh.

Peter

 


Comment 7 Markus Schönhaber 2008-07-25 05:12:23 UTC
(In reply to comment #6)

> I can't start tomcat with this patch at Mac OS X ( 10.4.11).

I've just tried this with Rémy's 6.0.18 buildon Ubuntu Hardy and it works fine - regardless whether or not CATALINA_BASE contains spaces. So, this seems to be a MacOS-specific issue.

WAG: What's /bin/sh on MacOS? Does altering the shebang in catalina.sh to
#!/bin/bash
help?
Comment 8 Rainer Jung 2008-07-25 05:58:43 UTC
Hi Peter,

see

http://marc.info/?l=tomcat-dev&m=121622230731754&w=2

Comment 9 Mark Thomas 2008-08-27 13:51:42 UTC
This has been fixed in 5.5.x and will be included in 5.5.27 onwards