如何通过终端命令将Web应用程序部署到tomcat应用程序服务器 [英] How can I deploy a web application to tomcat application server via Terminal command
问题描述
我目前正在测试大量的Web服务.我想通过终端命令尽快部署和取消部署到tomcat应用服务器.对于需要部署的大量Web服务,使用HTML GUI是不合理的.谁能协助我,如何通过终端命令进行部署?
I am currently testing a large number of webservices. I would like to deploy and undeploy to tomcat application server via terminal command as fast as I can. Using the HTML GUI would not be reasonable for the large number of webservices that I need to deploy. Can anyone assist me, in how to deploy via a terminal command?
此外,我正在编写一个自动执行部署过程的ash脚本,因此,如果有人可以给我一些指导,那就太好了.
Furthermore, I am writing a ash script that automates the deployment process, so perhaps if someone can give me some some direction it would be great.
理想情况下,我希望在命令行上执行以下操作:
Ideally, I am looking to do something like this on the command line:
TOMCAT --parameter指定WAR文件的路径--parameter2-指定某种配置文件
TOMCAT --parameter Specify path to WAR file --parameter2 --specify some sort of config file
推荐答案
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":
- 找出tomcat的安装位置.您可以在bash中执行此操作:
catalina版本
- 导航到CATALINA_HOME配置目录,该目录显示在上一条命令的输出中.
cd /usr/local/Cellar/tomcat/8.0.22/libexec/conf
- 注意:在我的示例中,我使用自制软件安装了tomcat 8,用您的命令行输出中显示的内容替换了此路径.
- 验证 server.xml 是否包含 UserDatabase 资源(如果未添加):
- Verify that the server.xml contains a UserDatabase resource (if it doesn't add it):
<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 了解更多信息.
- 然后确认 config/user-tomcat.xml 存在并且看起来像这样:
- Then verify that config/user-tomcat.xml exists and looks like this:
<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解决问题.
*注意:使用wget开始向tomcat部署战争时,需要先启动tomcat. - 现在执行以下命令:
- First restart your server to pick up any configuration changes that you may have done.
catalina stop
, thencatalina start
, will do the trick from bash.
*Note: When using wget to start deploy a war to tomcat, tomcat needs to be started first. - Now execute the following command:
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://localhost:8080/app/来查看您的Web应用.
- Now go to http://localhost:8080/app/ to see your webapp.
-
请等待几秒钟,以使http请求发送并完全部署该战争.(有时需要一段时间).
Wait a few seconds to let the http request to send and fully deploy the war. (sometimes this takes a while).
- 将插件添加到pom.xml:
注释:
您可能会喜欢使用主目录快捷方式(例如 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>
- 导航到项目根目录( pom.xml 所在的位置),然后运行以下命令:
mvn tomcat7:run
这篇关于如何通过终端命令将Web应用程序部署到tomcat应用程序服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!