1、下载:
从apache官网(http://tomcat.apache.org/ )上下载最新的tomcat二进制包(注:是mac版本的.gz文件包)
2、将上述二进制包解压后改名为Tomcat,并复制到/Library目录下
新建Finder窗口—— shift + Command + G —— 输入/Library,进入此目录
将Tomcat文件夹复制到此目录下
3、修改权限
方式一:选中Tomcat文件夹 , Command+i 打开简介, 修改文件权限。
方式二:打开终端,输入sudo chmod 755 /Library/Tomcat
4、执行/Library/Tomcat/bin目录下的startup.sh文件
在终端输入命令:sudo sh startup.sh 或者 sudo ./startup.sh start命令启动tomcat
在终端输入命令:sudo sh shutdown.sh 或者 sudo ./shutdown.sh stop命令关闭tomcat
5、验证tomcat是否安装成功
从apache官网(http://tomcat.apache.org/ )上下载最新的tomcat二进制包(注:是mac版本的.gz文件包)
2、将上述二进制包解压后改名为Tomcat,并复制到/Library目录下
新建Finder窗口—— shift + Command + G —— 输入/Library,进入此目录
将Tomcat文件夹复制到此目录下
3、修改权限
方式一:选中Tomcat文件夹 , Command+i 打开简介, 修改文件权限。
方式二:打开终端,输入sudo chmod 755 /Library/Tomcat
4、执行/Library/Tomcat/bin目录下的startup.sh文件
在终端输入命令:sudo sh startup.sh 或者 sudo ./startup.sh start命令启动tomcat
在终端输入命令:sudo sh shutdown.sh 或者 sudo ./shutdown.sh stop命令关闭tomcat
5、验证tomcat是否安装成功
启动tomcat后,打开http://localhost:8080查看是否Tomcat已经启动。
tomcat的安装步骤就这样完成了,下面我将为大家介绍一个脚本,方便启动和终止tomcat:
配置Tomcat启动脚本:
使用文本编辑器添加以下代码:
#!/bin/bash
case $1 in
start)
sh /Library/Tomcat/bin/startup.sh
;;
stop)
sh /Library/Tomcat/bin/shutdown.sh
;;
restart)
sh /Library/Tomcat/bin/shutdown.sh
sh /Library/Tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac
start)
sh /Library/Tomcat/bin/startup.sh
;;
stop)
sh /Library/Tomcat/bin/shutdown.sh
;;
restart)
sh /Library/Tomcat/bin/shutdown.sh
sh /Library/Tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac
exit 0
将文件保存为tomcat,小写并不带后缀。赋予文件执行权限:chmod 777 tomcat
将这个文件放置到终端包含的路径中,例如/usr/bin,而后便可以在终端中简单地输入tomcat start和tomcat stop启用tomcat了。
快捷命令如下:
1)tomcat start
2) tomcat stop
3) tomcat restart
但是我在用这个脚本启动的时候也遇到一个问题,我开始用sudo sh startup.sh/shutdown.sh命令时能正常的启动与终止,但是当我用刚刚的脚本时就出现如下错误:
bogon:Desktop admin$ tomcat start
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
touch: /Library/Tomcat/logs/catalina.out: Permission denied
/Library/Tomcat/bin/catalina.sh: line 387: /Library/Tomcat/logs/catalina.out: Permission denied
bogon:Desktop admin$ tomcat restart
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
2013-10-31 22:20:51 org.apache.catalina.startup.Catalina stopServer
????: Could not contact localhost:8005. Tomcat may not be running.
2013-10-31 22:20:51 org.apache.catalina.startup.Catalina stopServer
????: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:382)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:241)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:228)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:431)
at java.net.Socket.connect(Socket.java:527)
at java.net.Socket.connect(Socket.java:476)
at java.net.Socket.<init>(Socket.java:373)
at java.net.Socket.<init>(Socket.java:187)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:500)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:371)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:458)
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
touch: /Library/Tomcat/logs/catalina.out: Permission denied
/Library/Tomcat/bin/catalina.sh: line 387: /Library/Tomcat/logs/catalina.out: Permission denied
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
touch: /Library/Tomcat/logs/catalina.out: Permission denied
/Library/Tomcat/bin/catalina.sh: line 387: /Library/Tomcat/logs/catalina.out: Permission denied
bogon:Desktop admin$ tomcat restart
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
2013-10-31 22:20:51 org.apache.catalina.startup.Catalina stopServer
????: Could not contact localhost:8005. Tomcat may not be running.
2013-10-31 22:20:51 org.apache.catalina.startup.Catalina stopServer
????: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:382)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:241)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:228)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:431)
at java.net.Socket.connect(Socket.java:527)
at java.net.Socket.connect(Socket.java:476)
at java.net.Socket.<init>(Socket.java:373)
at java.net.Socket.<init>(Socket.java:187)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:500)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:371)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:458)
Using CATALINA_BASE: /Library/Tomcat
Using CATALINA_HOME: /Library/Tomcat
Using CATALINA_TMPDIR: /Library/Tomcat/temp
Using JRE_HOME: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Using CLASSPATH: /Library/Tomcat/bin/bootstrap.jar:/Library/Tomcat/bin/tomcat-juli.jar
touch: /Library/Tomcat/logs/catalina.out: Permission denied
/Library/Tomcat/bin/catalina.sh: line 387: /Library/Tomcat/logs/catalina.out: Permission denied
上网查了好多资料终于解决这个问题了,这是由于权限不够所导致的。我把这个脚本修改如下:
#!/bin/bash
case $1 in
start)
sudo sh /Library/Tomcat/bin/startup.sh
;;
stop)
sudo sh /Library/Tomcat/bin/shutdown.sh
;;
restart)
sudo sh /Library/Tomcat/bin/shutdown.sh
sudo sh /Library/Tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac
start)
sudo sh /Library/Tomcat/bin/startup.sh
;;
stop)
sudo sh /Library/Tomcat/bin/shutdown.sh
;;
restart)
sudo sh /Library/Tomcat/bin/shutdown.sh
sudo sh /Library/Tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac
exit 0
这样就没问题啦。
如果遇到诸如无法找到目录以及文件地问题,一般是因为文件权限造成地问题,可以如此解决:
sudo chmod 755 /Library/Tomcat/bin/*.sh
sudo chmod 755 /Library/Tomcat/bin/*.bat
sudo chmod 755 /Library/Tomcat/bin/*.bat
遇见”JAVA_HOME not defined”JAVA路径未定义错误,在终端中执行以下命令:
sudo setenv JAVA_HOME /Library/Java/Home
sudo setenv JAVA_HOME /Library/Java/Home