java 向 tomcat 部署一场战争
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9951763/
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
Deploy a war to tomcat
提问by krakover
In the past 10 years or so, I had the opportunity to deploy web applications into a tomcat countless times. I also wrote several scripts trying to do that automatically, but never managed to completely automate it.
在过去 10 年左右的时间里,我有无数次将 Web 应用程序部署到 tomcat 中的机会。我还写了几个脚本试图自动执行此操作,但从未设法使其完全自动化。
Here is the issue. I am trying to deploy a new war, with the same name as an existing war in the webapps of my tomcat.
这是问题。我正在尝试部署一个新的War,与我的 tomcat 的 webapps 中的现有War同名。
Option 1: The naive approach - just copy the war and wait for it to update the exploded directory. This sometimes work. Many times - the exploded directory is not updated in a reasonable time.
Option 2: The through approach - stop the tomcat, delete all the wars and temporary files. copy the war and start the tomcat. This usually involves stopping the tomcat, waiting for a while - and then checking to see if the process is still alive and killing it.
Option 3: The manual approach - This might be surprising, but I found it to work many of the times - copy the war, wait for the exploded directory to be updated, and once it does -
restart the tomcat. if it doesn't - you can try to delete the temporary work files, and that sometimes help.
选项 1:天真的方法 - 只需复制 war 并等待它更新分解的目录。这有时有效。很多时候 - 分解的目录没有在合理的时间内更新。
选项 2:通过方法 - 停止 tomcat,删除所有War和临时文件。复制War并启动tomcat。这通常涉及停止 tomcat,等待一段时间 - 然后检查进程是否还活着并杀死它。
选项 3:手动方法 - 这可能令人惊讶,但我发现它在很多时候都可以工作 - 复制War,等待分解的目录更新,一旦更新 - 重新启动 tomcat。如果没有 - 您可以尝试删除临时工作文件,这有时会有所帮助。
I also tried many options - with different order and subset of the actions - restart, stop, delete war, delete exploded, delete localhost context, delete localhost work directory, copy war, sleep, compare dates, ask the tomcat politely to reload, etc. Nothing seemed to just work.
我还尝试了许多选项 - 使用不同的顺序和操作子集 - 重新启动、停止、删除War、删除爆炸、删除本地主机上下文、删除本地主机工作目录、复制War、睡眠、比较日期、礼貌地要求 tomcat 重新加载等. 似乎什么都不起作用。
It might be something that I am doing wrong, but I've heard the same experience from numerous people, so I'm here to get some advice - what say you? What is the best way to deploy a new war to a tomcat?
这可能是我做错了,但我从很多人那里听到了同样的经历,所以我来这里是为了得到一些建议 - 你怎么说?将新War部署到 tomcat 的最佳方法是什么?
Thanks!
谢谢!
回答by systemkern
you can easily automate this in a shell script with curl
您可以使用 curl 在 shell 脚本中轻松自动执行此操作
on tomcat 6:
在 tomcat 6 上:
curl --upload-file deployme.war "http://tomcat:s3cret@localhost:8088/manager/deploy?path=/deployme&update=true"
on tomcat 7
在 tomcat 7 上
curl -T "deployme.war" "http://tomcat:s3cret@localhost:8080/manager/text/deploy?path=/deployme&update=true"
or via almost any porgramming language. I posted a java based solution here
或通过几乎任何语言编写。我在这里发布了一个基于 Java 的解决方案
回答by Glenn
I tend to go for Option 2. If there is a project I am working on in the ide especially with a debugger attached, I find things eventually start getting messed up. Might be chasing a red herring for an hour before I discover clearing everything away makes the problem go away. Then it is nice to have a script on the side that I can occasionally launch to clear everything up:
我倾向于选择选项 2。如果我正在 ide 中处理一个项目,尤其是附加了调试器的项目,我会发现事情最终开始变得一团糟。在我发现清除所有东西使问题消失之前,可能会追逐一个小时的红鲱鱼。然后很高兴有一个脚本,我可以偶尔启动它以清除所有内容:
- shutdown force with a 60s timeout
- clear out the log, temp, work directories
- clear out the webapp folder
- copy in the new war file from the build location
- explode the new war file
- if necessary, run an awk script to customize machine specific values in the properties files (hence the previous explode)
- startup with the CATALINA_PID environment variable set (to enable the shutdown force)
- 60 秒超时的关闭强制
- 清除日志、临时、工作目录
- 清除 webapp 文件夹
- 从构建位置复制新的war文件
- 爆炸新的War文件
- 如有必要,运行 awk 脚本以自定义属性文件中特定于机器的值(因此之前的爆炸)
- 使用 CATALINA_PID 环境变量集启动(以启用关闭强制)
Normally things shutdown nicely. If not, then there is usually a background thread that was started up but missing a shutdown hook (say a memecached client) and needs to be hunted down. Normally, just dropping in the new war seems to work to. But if in a dev environment, a script for doing the full blown restart is nice.
通常情况下,事情会很好地关闭。如果没有,那么通常有一个后台线程已启动但缺少关闭挂钩(例如 memecached 客户端)并且需要被追捕。通常情况下,在新的War中加入似乎是有效的。但是,如果在开发环境中,用于执行完全重启的脚本很好。
回答by Thorbj?rn Ravn Andersen
Cargo - http://cargo.codehaus.org/- can be used to remotely deploy WAR files to a number of web containers, Tomcat included.
Cargo - http://cargo.codehaus.org/- 可用于将 WAR 文件远程部署到许多 Web 容器,包括 Tomcat。
See http://cargo.codehaus.org/Quick+startfor examples in Java. Ant and Maven support is also available.
有关Java 示例,请参阅http://cargo.codehaus.org/Quick+start。Ant 和 Maven 支持也可用。
回答by Kaleb Brasee
I upload the WAR to my home directory, cd to /usr/local/tomcat, then run the following commands:
我将 WAR 上传到我的主目录,cd 到 /usr/local/tomcat,然后运行以下命令:
bin/shutdown.sh
rm webapps/ROOT.war
rm -rf webapps/ROOT
cp ~/ROOT.war webapps
bin/startup.sh
Easy enough to automate, but I've been too lazy (or not lazy enough) to do that thus far.
很容易实现自动化,但到目前为止我太懒了(或不够懒惰)而无法做到这一点。
回答by Tony Ennis
I just use the Tomcat management tool to stop the process, remove it, and install the new WAR. Easy peasy.
我只是使用 Tomcat 管理工具停止该进程,将其删除,然后安装新的 WAR。十分简单。
回答by Matt
See the section on "Deploying using the Client Deployer Package"
请参阅“使用客户端部署程序包进行部署”部分
It's basically a ready made ant script to perform common tomcat deployment operations.
它基本上是一个现成的 ant 脚本,用于执行常见的 tomcat 部署操作。
http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html#Deploying_on_a_running_Tomcat_server
http://tomcat.apache.org/tomcat-7.0-doc/deployer-howto.html#Deploying_on_a_running_Tomcat_server