Mac 中安装 tomcat 及 Eclipse 配置 Tomcat
Posted GoldenaArcher
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac 中安装 tomcat 及 Eclipse 配置 Tomcat相关的知识,希望对你有一定的参考价值。
Mac 中安装 tomcat 及 Eclipse 配置 Tomcat
用 homebrew 安装就挺无痛的啦……
安装 tomcat
指令如下:
# 可能需要 update 一下,默认下载的 tomcat 版本为10
# 不过我看的教程用9,所以这里就用 @9
➜ ~ brew install tomcat@9
# 因为 9 不是默认指定的版本,所以需要讲 path 加到 zshrc 中
# 这个也会根据使用什么终端而产生变化
# 如果把 mac 当 linux 用,应该是就是 bashrc 或者 bash_profile
➜ ~ echo 'export PATH="/usr/local/opt/tomcat@9/bin:$PATH"' >> ~/.zshrc
然后运行:
➜ ~ catalina run
Using CATALINA_BASE: /usr/local/Cellar/tomcat@9/9.0.68/libexec
Using CATALINA_HOME: /usr/local/Cellar/tomcat@9/9.0.68/libexec
Using CATALINA_TMPDIR: /usr/local/Cellar/tomcat@9/9.0.68/libexec/temp
Using JRE_HOME: /Users/louhan/.sdkman/candidates/java/current
Using CLASSPATH: /usr/local/Cellar/tomcat@9/9.0.68/libexec/bin/bootstrap.jar:/usr/local/Cellar/tomcat@9/9.0.68/libexec/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
24-Oct-2022 14:45:55.518 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.68
24-Oct-2022 14:45:55.520 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Oct 3 2022 19:06:10 UTC
24-Oct-2022 14:45:55.520 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.68.0
24-Oct-2022 14:45:55.520 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Mac OS X
24-Oct-2022 14:45:55.520 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 12.6
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: x86_64
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /Users/louhan/.sdkman/candidates/java/11.0.16-ms
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 11.0.16+8-LTS
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Microsoft
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/local/Cellar/tomcat@9/9.0.68/libexec
24-Oct-2022 14:45:55.521 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/local/Cellar/tomcat@9/9.0.68/libexec
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
24-Oct-2022 14:45:55.568 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/Cellar/tomcat@9/9.0.68/libexec/conf/logging.properties
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/Cellar/tomcat@9/9.0.68/libexec
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/Cellar/tomcat@9/9.0.68/libexec
24-Oct-2022 14:45:55.569 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/Cellar/tomcat@9/9.0.68/libexec/temp
24-Oct-2022 14:45:55.581 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [/Users/louhan/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.]
24-Oct-2022 14:45:55.861 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
24-Oct-2022 14:45:55.908 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [586] milliseconds
24-Oct-2022 14:45:55.962 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
24-Oct-2022 14:45:55.963 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.68]
24-Oct-2022 14:45:55.973 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/docs]
24-Oct-2022 14:45:56.268 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/docs] has finished in [295] ms
24-Oct-2022 14:45:56.269 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/manager]
24-Oct-2022 14:45:56.305 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/manager] has finished in [36] ms
24-Oct-2022 14:45:56.305 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/examples]
24-Oct-2022 14:45:56.515 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/examples] has finished in [209] ms
24-Oct-2022 14:45:56.515 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/ROOT]
24-Oct-2022 14:45:56.532 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/ROOT] has finished in [17] ms
24-Oct-2022 14:45:56.533 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/host-manager]
24-Oct-2022 14:45:56.552 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/Cellar/tomcat@9/9.0.68/libexec/webapps/host-manager] has finished in [19] ms
24-Oct-2022 14:45:56.556 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
24-Oct-2022 14:45:56.567 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [658] milliseconds
效果如下:
总体来说使用 homebrew 进行安装还是非常方便的,提示什么的也做得挺好的,而且也不需要运行 sudo chmod 755 *.sh
就可以直接使用 catalina
。
关于使用 sdkman 安装 tomcat
步骤大概是一样的,不过我有遇到过权限问题,思考一下大概是因为没有做 sudo chmod 755 *.sh
的关系。
不过鉴于已经使用 homebrew 安装好了 tomcat,就没有继续折腾 sdkman。如果之后有版本管理的需求,应该会折腾一下 sdkman……毕竟真的方便。
Eclipse 中配置 Tomcat
这点和在 Windows 上配置没有什么比较大的区别,首先就是找到 Servers 这个 tab(需要在 JavaEE 模式下才能看到):
如果没有服务器的话应该会有一个加号,需要新建一个也可以右键然后 new 一个。随后直接搜索 tomcat,然后选中指定版本:
随后会显示这个界面:
可以让 Eclipse 自己安装一个 Tomcat 的服务器。如果是按照上面用 homebrew 下载好的话,路径就是 /usr/local/opt/tomcat@9/libexec
。
注意: 不是 bin
,而是 libexec
。
配置完了应该就能看到最初的这个界面了:
以上是关于Mac 中安装 tomcat 及 Eclipse 配置 Tomcat的主要内容,如果未能解决你的问题,请参考以下文章