Java 在Tomcat上部署war文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/142548/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deployment of war file on Tomcat
提问by Milhous
Is there a way to deploy a given war file on Tomcat server? I want to do this without using the web interface.
有没有办法在Tomcat服务器上部署给定的war文件?我想在不使用 Web 界面的情况下执行此操作。
采纳答案by Joe Dean
Just copy the war file into the $TOMCAT_HOME/webapps/ directory. Tomcat will deploy the war file by automatically exploding it. FYI - If you want you can make updates directly to the exploded directory, which is useful for development.
只需将 war 文件复制到 $TOMCAT_HOME/webapps/ 目录中即可。Tomcat 将通过自动分解来部署 war 文件。仅供参考 - 如果您愿意,可以直接对展开的目录进行更新,这对开发很有用。
回答by anjanb
you can edit the conf/server.xml and add an entry like this pointing to your war directory
您可以编辑 conf/server.xml 并添加这样的条目指向您的 war 目录
<Context path="/strutsDisplayTag"
reloadable="true"
docBase="C:\work\learn\jsp\strutsDisplayTag"
workDir="C:\work\learn\jsp\strutsDisplayTag\work" />
ELSE you can copy your .WAR file to the webapps directory of tomcat.
否则,您可以将 .WAR 文件复制到 tomcat 的 webapps 目录中。
回答by dacracot
We never use the web interface, don't like it. The wars are dropped in the webapps and server.xml edited as necessary. You need to bounce it if you edit the server.xml, but the war file should be picked up automagically. We generally delete the directory expanded from the war first so there is no confusion from where the components came.
我们从不使用网络界面,不喜欢它。战争被丢弃在 webapps 和 server.xml 中,根据需要进行编辑。如果您编辑 server.xml,则需要将其退回,但应自动拾取 war 文件。我们通常先删除从战争中扩展的目录,这样就不会混淆组件来自哪里。
回答by John Meagher
The Tomcat Client Deployer Packagelooks to be what you need to deploy to a remote server from the command line. From the page:
Tomcat客户端部署程序包看起来是您需要从命令行部署到远程服务器的程序包。从页面:
This is a package which can be used to validate, compile, compress to .WAR, and deploy web applications to production or development Tomcat servers. It should be noted that this feature uses the Tomcat Manager and as such the target Tomcat server should be running.
这是一个包,可用于验证、编译、压缩为 .WAR,以及将 Web 应用程序部署到生产或开发 Tomcat 服务器。应该注意的是,此功能使用 Tomcat 管理器,因此目标 Tomcat 服务器应该正在运行。
回答by Aleksandar Dimitrov
There are several ways to deploy a Tomcat webapp:
部署Tomcat webapp有以下几种方式:
- Dropping into $CATALINA_HOME/webapps, as was already mentioned.
- Using your build scripts to deploy automatically via the manager interface (that comes with Tomcat). Here are the two ways
- for Maven: use the tomcat plugin. You don't need to include it in
pom.xml
, just issue the goalmvn tomcat:deploy
, the plugin is included in Maven 2. This assumes several defaults explained in the documentation, you can configurethe behaviour in thepom.xml
. There are other goals that let you deploy as an exploded archive etc. - for Ant: something like this:
- for Maven: use the tomcat plugin. You don't need to include it in
- 如前所述,放入 $CATALINA_HOME/webapps。
- 使用您的构建脚本通过管理器界面(Tomcat 附带的)自动部署。这里有两种方式
<property name="manager.url" value="http://localhost:8080/manager"/> <property name="manager.username" value="manager"/> <property name="manager.password" value="foobar"/> <!-- Task definitions --> <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"/> <taskdef name="list" classname="org.apache.catalina.ant.ListTask"/> <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask"/> <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask"/> <!-- goals --> <target name="install" depends="compile" description="Install application to servlet container"> <deploy url="${manager.url}" username="${manager.username}" password="${manager.password}" path="${app.path}" localWar="file://${build.home}"/> </target> <target name="list" description="List installed applications on servlet container"> <list url="${manager.url}" username="${manager.username}" password="${manager.password}"/> </target> <target name="reload" depends="compile" description="Reload application on servlet container"> <reload url="${manager.url}" username="${manager.username}" password="${manager.password}" path="${app.path}"/> </target> <target name="remove" description="Remove application on servlet container"> <undeploy url="${manager.url}" username="${manager.username}" password="${manager.password}" path="${app.path}"/> </target>
All of those will require you to have a Tomcat user configuration. It lives $CATALINA_BASE/conf/tomcat-users.xml
, but since you know already how to use the web interface, I assume you know how to configure the users and passwords.
所有这些都需要你有一个 Tomcat 用户配置。它存在$CATALINA_BASE/conf/tomcat-users.xml
,但由于您已经知道如何使用 Web 界面,我假设您知道如何配置用户和密码。
回答by kotfu
You can also try this command-line script for managing tomcatcalled tomcat-manager. It requires Python, and talks to the manager application included with tomcat via HTTP. You can do stuff from a *nix shell like:
您还可以尝试使用这个命令行脚本来管理名为 tomcat-manager 的 tomcat。它需要 Python,并通过 HTTP 与包含在 tomcat 中的管理器应用程序对话。您可以从 *nix shell 执行以下操作:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager/ stop /myapp
and:
和:
$ tomcat-manager --user=admin --password=newenglandclamchowder \
> http://localhost:8080/manager deploy /myapp ~/src/myapp/myapp.war