MacPorts で Tomcat 6 をインストールする

インストールする前に

で実行している。

% java -version
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)

Tomcat 6 をインストールする

でも、失敗するんだけれど…。

% sudo port -d install tomcat6
build-prepare:
   [delete] Deleting directory /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/output/build/temp
    [mkdir] Created dir: /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/output/build/temp

compile:
    [javac] Compiling 1052 source files to /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/output/classes
    [javac] 
    [javac] 
    [javac] ƒVƒXƒeƒ€ƒŠƒ\[ƒX‚ª•s‘«‚µ‚Ă¢‚܂·B
    [javac] ڍׂ͎Ÿ‚̃Xƒ^ƒbƒNƒgƒŒ[ƒX‚Œ²¸‚µ‚Ă­‚¾‚³‚¢B
    [javac] java.lang.OutOfMemoryError: Java heap space
BUILD FAILED
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/build.xml:119: Compile failed; see the compiler error output for details.

原因

エラーメッセージにあるメモリ不足だ。

    [javac] java.lang.OutOfMemoryError: Java heap space

解決方法

Ant の build.xml を修正する。

% ls -l /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/
total 424
-rw-r--r--   1 root  admin   4838  5 14  2009 BUILDING.txt
-rw-r--r--   1 root  admin  20528  5 14  2009 KEYS
-rw-r--r--   1 root  admin  37951  5 14  2009 LICENSE
-rw-r--r--   1 root  admin    556  5 14  2009 NOTICE
-rw-r--r--   1 root  admin   7320  5 14  2009 RELEASE-NOTES
-rw-r--r--   1 root  admin   2392  5 14  2009 RELEASE-PLAN-6.0.txt
-rw-r--r--   1 root  admin   6368  5 14  2009 RUNNING.txt
drwxr-xr-x   8 root  admin    272  4 21 22:21 Repository
-rw-r--r--   1 root  admin   6616  5 14  2009 STATUS.txt
drwxr-xr-x  20 root  admin    680  4 21 22:13 bin
-rw-r--r--   1 root  admin   4698  5 14  2009 build.properties.default
-rw-r--r--   1 root  wheel  29211  4 21 22:13 build.xml
-rw-r--r--   1 root  admin  29202  5 14  2009 build.xml.orig
drwxr-xr-x   9 root  admin    306  4 21 22:13 conf
-rw-r--r--   1 root  admin  23807  5 14  2009 dist.xml
-rw-r--r--   1 root  admin  11384  5 14  2009 extras.xml
drwxr-xr-x   4 root  admin    136  5 14  2009 java
drwxr-xr-x   3 root  admin    102  5 14  2009 native
drwxr-xr-x   4 root  admin    136  4 21 22:21 output
drwxr-xr-x  25 root  admin    850  4 21 22:13 res
drwxr-xr-x   4 root  admin    136  4 21 22:13 test
drwxr-xr-x   7 root  admin    238  5 14  2009 webapps
% sudo vi /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_java_tomcat6/work/apache-tomcat-6.0.20-src/build.xml

修正内容は下記の通り。
修正前の build.xml は次の通り。

<javac srcdir="java" destdir="${tomcat.classes}"
    debug="${compile.debug}"
    deprecation="${compile.deprecation}"
    source="${compile.source}"
    target="${compile.target}"
    optimize="${compile.optimize}"
    excludes="**/CVS/**,**/.svn/**">

これに下記 3行を追加する。

  1. fork="true"
  2. memoryinitialsize="256m"
  3. memorymaximumsize="256m"

修正すると次のようになる。

<javac srcdir="java" destdir="${tomcat.classes}"
    debug="${compile.debug}"
    deprecation="${compile.deprecation}"
    source="${compile.source}"
    target="${compile.target}"
    optimize="${compile.optimize}"
    excludes="**/CVS/**,**/.svn/**"
    fork="true"
    memoryinitialsize="256m"
    memorymaximumsize="256m">

修正ができたら、build.xml を保存して、再度 Tomcat 6 のインストールをする。

Tomcat 6 を再度インストールする

% sudo port install tomcat6

成功すると、下記のメッセージが表示される。

###########################################################
# A startup item has been generated that will aid in
# starting tomcat6 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo launchctl load -w /Library/LaunchDaemons/org.macports.tomcat6.plist
###########################################################
--->  Installing tomcat6 @6.0.20_0
#
# Configuration files in /opt/local/share/java/tomcat6/conf have been
# installed with a .sample extension so that they won't be replaced by a
# port update. Each will be copied to its proper location during the
# first startup of tomcat by catalina.sh or tomcatctl if you don't
# do this yourself first. If this _is_ an update, you might do a diff to
# verify that you're not missing anything in the newer .sample versions
# of these files.
#
# The script /opt/local/share/java/tomcat6/bin/tomcatctl has been installed to
# facilitate start and stop of tomcat using the jsvc utility, which allows you to
# start tomcat as a true daemon process. Once tomcat has acquired its TCP socket,
# jsvc will drop its root privileges and run as user www.
#
# Under Apple Java, control over the Java version used to launch tomcat6 is
# through the shell variable JAVA_JVM_VERSION. This variable should be set
# to a java version such as 1.5, 1.6, or CurrentJDK (for the default version).
# You may set JAVA_JVM_VERSION in /opt/local/share/java/tomcat6/bin/setenv.sh.
#

Tomcat 6 をデーモンとして起動したい場合は、

% sudo launchctl load -w /Library/LaunchDaemons/org.macports.tomcat6.plist

を実行する。ユーザー側で任意に起動・停止をしたい場合は、次のようにする。
起動の場合は、

% sudo /opt/local/share/java/tomcat6/bin/tomcatctl start
Password:
conf_setup.sh: file conf/catalina.policy is missing; copying conf/catalina.policy.sample to its place.
conf_setup.sh: file conf/catalina.properties is missing; copying conf/catalina.properties.sample to its place.
conf_setup.sh: file conf/server.xml is missing; copying conf/server.xml.sample to its place.
conf_setup.sh: file conf/tomcat-users.xml is missing; copying conf/tomcat-users.xml.sample to its place.
conf_setup.sh: file conf/web.xml is missing; copying conf/web.xml.sample to its place.
conf_setup.sh: file conf/setenv.local is missing; copying conf/setenv.local.sample to its place.
Starting Tomcat.... started. (pid 504)

停止の場合は

% sudo /opt/local/share/java/tomcat6/bin/tomcatctl stop

と実行する。

注意点

Mac OS X で使っている Java のバージョンによっては、Tomcat 6 が正常に起動しない場合がある。
その場合は、下記を参考にして何とかする…。

You have to install Java 1.5 from your Leopard CD or download it:

  1. Download the official Java package from Apple, “Java for Mac OS X 10.5 Update 4” dated June 15, 2009. Don't try with version 5 or 6.
  2. Meanwhile, go to /System/Library/Frameworks/JavaVM.framework/Versions and delete the two aliases (symlinks) “1.5” and “1.5.0”.
  3. Open "Java for Mac OS X 10.5 Update 4” with Pacifist, and drill down into Contents > System > Library > Frameworks > JavaVM.framework > Versions
  4. Still in Pacifist, select 1.5 and 1.5.0, right-click, and chose "Install to Default Location".
  5. Uncomment this line in /opt/local/share/java/tomcat6/conf/setenv.local #export JAVA_JVM_VERSION=1.5
  6. Start tomcat
https://trac.macports.org/ticket/22787