Java 如何自动将战争从 Nexus 部署到 Tomcat?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22569710/
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
How can I automatically deploy a war from Nexus to Tomcat?
提问by Nital
How can I automatically deploy a war from Nexus to Tomcat?
如何自动将战争从 Nexus 部署到 Tomcat?
I have a maven web project which gets built and deployed (both SNAPSHOT and release versions) on Nexus successfully. I would like to know if there is feature/plugin in Nexus where it picks the released war and deploys on remote Tomcat automatically?
我有一个 maven web 项目,它在 Nexus 上成功构建和部署(包括快照和发布版本)。我想知道 Nexus 中是否有功能/插件可以选择已发布的战争并自动部署在远程 Tomcat 上?
I know that you can deploy the war to remote Tomcat using maven-tomcat-plugin but would like to know if there is an alternative solution.
我知道您可以使用 maven-tomcat-plugin 将战争部署到远程 Tomcat,但想知道是否有替代解决方案。
Please guide.
请指导。
采纳答案by Mark O'Connor
Typically you'd use a CI tool like Jenkins to run the Maven build that publishes your War file into Nexus. Nexus would then be used by whatever tool you're using to push the War onto the target tomcat environment:
通常你会使用像 Jenkins 这样的 CI 工具来运行 Maven 构建,将你的 War 文件发布到 Nexus 中。Nexus 将被您用来将 War 推送到目标 tomcat 环境的任何工具使用:
There are lots and lots of options.
有很多很多的选择。
Jenkins post build SSH script
Jenkins 后构建 SSH 脚本
Run a post-build SSH task from Jenkins that does something like this on the target tomcat server:
从 Jenkins 运行构建后的 SSH 任务,在目标 tomcat 服务器上执行以下操作:
curl "http://myrepo/nexus/service/local/artifact/maven/redirect?r=releases&g=myorg&a=myapp&v=1.1&e=war" \
-o /usr/local/share/tomcat7/webapps/myapp.war
service tomcat7 restart
Rundeck
跑台
My preference is to use Rundeckfor deployments, because it has a Nexus plugin, providing convenient drop-down menus of available releases.
我更喜欢使用Rundeck进行部署,因为它有一个Nexus 插件,提供可用版本的便捷下拉菜单。
There is also a Rundeck pluginfor Jenkins that can be used to orchestrate a CI process with Jenkins performing the build, hand-over to Rundeck for deployment, followed by a Jenkins call-back to run the integration tests.
还有一个适用于 Jenkins的Rundeck 插件,可用于编排 CI 流程,由 Jenkins 执行构建,移交给 Rundeck 进行部署,然后是 Jenkins 回调以运行集成测试。
Chef
厨师
I also use chef which can be used to automatically deploy software in a pull fashion.
我还使用了 Chef,它可用于以拉动方式自动部署软件。
The artifactcookbook has direct support for Nexus, whereas the application_javacookbook uses a more generic "pull from a URL" approach that also works well.
该神器的食谱具有的Nexus直接支持,而application_java食谱采用的办法,也是行之有效的一种更通用的“从URL拉”。
.. ..
……
The list goes on, so I hope this helps.
名单还在继续,所以我希望这会有所帮助。
回答by Jirong Hu
We used UrbanCode for the deployment automation, retrieves war from Artifactory/Nexus and deploy to the target server.
我们使用 UrbanCode 进行部署自动化,从 Artifactory/Nexus 检索战争并部署到目标服务器。
回答by isudarsan
I used the Nexus Rest-API, these endpoints downloads the artifact to Jenkins workspace.
我使用了 Nexus Rest-API,这些端点将工件下载到 Jenkins 工作区。
In order to deploy Snapshot & Release to Tomcat we can create a Jenkins parameterized job and pass the parameters to the REST endpoint, also to deploy to a server like Tomact "Deploy WAR/EAR" Jenkins plugin will help.
为了将 Snapshot & Release 部署到 Tomcat,我们可以创建一个 Jenkins 参数化作业并将参数传递给 REST 端点,也可以部署到像 Tomact 这样的服务器“部署 WAR/EAR”Jenkins 插件会有所帮助。
We can parameterize the endpoint and use as part of "Build" step along with "Execute Shell script" option for the build.
我们可以参数化端点并作为“构建”步骤的一部分与构建的“执行 Shell 脚本”选项一起使用。
wget --user=${UserName} --password=${Password} "http://192.168.49.131:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=${GroupId}&a=${ArtifactId}&v=${Version}&e=${TypeOfArtifact}" --content-disposition
Actual endpoints to Nexus looks something like below.
Nexus 的实际端点如下所示。
wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=snapshots&g=org.codezarvis.artifactory&a=hushly&v=0.0.1-SNAPSHOT&e=jar" --content-disposition
wget --user=admin --password=admin123 "http://localhost:8080/nexus/service/local/artifact/maven/redirect?r=releases&g=org.codezarvis.artifactory&a=hushly&v=0.0.5&e=jar" --content-disposition
Thanks
-Sudarshan
谢谢
-Sudarshan