更新时间:2023-08-28 11:11:16
First you need to make sure that tomcat-user.xml is configured with the correct users and roles. The minimum role configuration is "admin,manager-script":
catalina版本
cd /usr/local/Cellar/tomcat/8.0.22/libexec/conf
- 注意:在我的示例中,我使用自制软件安装了tomcat 8,用您的命令行输出中显示的内容替换了此路径.
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
默认情况下,tomcat使用内存数据库存储用户和角色.这是在conf/server.xml中配置的.并委派用户&conf/tomcat-users.xml文件中的角色声明.请参阅: http://tomcat.apache.org/tomcat-8.0-doc/realm-howto.html#UserDatabaseRealm 了解更多信息.
<tomcat-users xmlns="http://tomcat.apache.org/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd">
<role rolename="admin"/>
<role rolename="manager-script"/>
<user username="admin" roles="admin,manager-script" password="admin" />
</tomcat-users>
现在,您已经准备好发动战争!
Now, you're ready to deploy a war!
有两种方法可以做到这一点...
Here are two ways to do that...
使用wget:
wget 是一个漂亮的工具,可让您通过命令行执行http请求.我建议使用类似 homebrew 的包管理器进行安装,否则,您可以使用此
wget is a nifty tool that lets you do http requests via the command line. I recommend installing it using a package manager like homebrew, otherwise, you can install using this wget install guide.
catalina stop
,然后 catalina start
,将通过bash解决问题.catalina stop
, then catalina start
, will do the trick from bash.wget --http-user=admin --http-password=admin "http://localhost:8080/manager/text/deploy?war=file:/Users/yourusername/app/target/APP-1.0.0.war&path=/app"
注释:
请等待几秒钟,以使http请求发送并完全部署该战争.(有时需要一段时间).
Wait a few seconds to let the http request to send and fully deploy the war. (sometimes this takes a while).
您可能会喜欢使用主目录快捷方式(例如 file:〜/app/target/APP-1.0.0.war
)引用war文件,但这不会工作.
You may be tempted to reference the war file using the home directory shortcut like this file:~/app/target/APP-1.0.0.war
, but that won't work.
要取消部署战争,只需在wget命令中将 deploy
替换为 undeploy
.
To undeploy the war simply replace deploy
with undeploy
in the wget command.
使用Tomcat Maven插件:
If you have the source code, you can build and deploy the war yourself very easily with the tomcat7-maven-plugin. Note: At the time I wrote this there was no tomcat8-maven-plugin; the tomcat-7-maven-plugin works just fine for tomcat 8.
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>${version.tomcat.maven.plugin}</version>
<configuration>
<path>/${project.build.finalName}</path>
<configurationDir>${env.CATALINA_HOME}</configurationDir>
<additionalConfigFilesDir>${env.CATALINA_HOME}/conf</additionalConfigFilesDir>
<uriEncoding>${project.build.sourceEncoding}</uriEncoding>
</configuration>
</plugin>
mvn tomcat7:run