文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. 下载Tomcat并解压
首先下载Tomcat,这不必多说,下载地址为:http://tomcat.apache.org/
解压Tomcat,例如作者下载的apache-tomcat-7.0.70.zip,直接解压即可,解压后得到apache-tomcat-7.0.70文件夹。
2. 启动Tomcat的相关配置
首先需要给Tomcat的bin目录下的sh文件赋予可执行权限,命令如下:
$ sudo chmod 755 ~/MyEclipse/apache-tomcat-7.0.70/bin/*.sh
3. 启动和关闭Tomcat
启动和关闭Tomcat,即运行startup.sh,shutdown.sh文件有两种方式,命令如下:
- 方法一:
# 启动Tomcat
$ cd MyEclipse/apache-tomcat-7.0.70/bin/
$ sh startup.sh
Using CATALINA_BASE: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH: /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
Tomcat started.
# 关闭Tomcat
$ sh shutdown.sh
Using CATALINA_BASE: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH: /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
- 方法二:
# 启动Tomcat
$ ./startup.sh start
Using CATALINA_BASE: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH: /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
Tomcat started.
# 关闭Tomcat
$ ./shutdown.sh shutdown
Using CATALINA_BASE: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_HOME: /Users/***/MyEclipse/apache-tomcat-7.0.70
Using CATALINA_TMPDIR: /Users/***/MyEclipse/apache-tomcat-7.0.70/temp
Using JRE_HOME: /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
Using CLASSPATH: /Users/***/MyEclipse/apache-tomcat-7.0.70/bin/bootstrap.jar:/Users/***/MyEclipse/apache-tomcat-7.0.70/bin/tomcat-juli.jar
usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help | start | stop }
4. 配置Tomcat
在启动Tomcat后,发现进入不了Manage APP,需要在Tomcat中配置用户名和密码,找到Tomcat目下的conf目录,编辑tomcat-users.xml,在<tomcat-users>标签下加入下面两行代码,即配置了Manage APP的用户名和密码为tomcat,tomcat:
<tomcat-users>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
</tomcat-users>
至此,Tomcat就在Mac下配置完成了,能启动关闭,当然也可以在Manage APP中发布应用,也可以直接将应用放到Tomcat下的webapps目录下。
注:当然可以把Tomcat配置在环境变量中,这个可以自行Google或百度。