使用Spring和Maven时,将代码部署到服务器的最佳方法是什么? [英] When using Spring and Maven, what is the best way to deploy the code to the server?

查看:93
本文介绍了使用Spring和Maven时,将代码部署到服务器的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Spring的项目。我每次部署时,都会运行maven目标package,它运行所有的测试并创建war文件。然后我手动使用ftp程序将war文件复制到服务器。然后我运行一个bash脚本来关闭服务器,替换war并再次启动服务器。



有时,当对数据库模式进行更改时,我必须手动运行一个sql迁移脚本。





对我来说双重不好,因为在DSL上,上传带宽杀死下载带宽,所以互联网是完全无法操作的。即使在项目和运行的maven目标是缓慢的,因为他们使用互联网连接一直寻找依赖。



有更好的工作方式吗?谢谢。

解决方案

首先,您可以通过使用Maven Deploy插件来避免手动的ftp副本。
您可以在此URL中找到通过ftp部署项目的方法:



http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html



第二点是关于您的项目的问题:您的WAR大小是否正常?

我听说过嵌入多余的jar的配置以避免在构建最终的jar时发生META-INF / spring.handlers覆盖的问题。如果您处于这种情况,您可能也对此感兴趣:



http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html


I have a project that uses Spring. Every time I deploy, I run the maven goal "package", which runs all the tests and creates the war file. Then I manually use an ftp program to copy the war file to the server. I then run a bash script to shut down the server, replace the war and start up the server again.

Sometimes when they are changes done to the database schema, I have to run a sql migration script manually.

Is there a better workflow I can use? As the project's war file gets to be 60MB, I am having to wait 10-12 minutes to upload it to the server. If I realize that one little thing needs to be changed, I have to do the whole process all over again.

It's doubly bad for me because on DSL, upload bandwidth kills download bandwidth, so the internet is completely inoperable. Even working on the project and running maven goals is slow because they use the internet connection to look for dependencies all the time.

Is there a better way to work? Thanks.

解决方案

First of all you could avoid manual ftp copies by using the Maven Deploy plugin. You can find an how-to to deploy projects over ftp at this URL:

http://maven.apache.org/plugins/maven-deploy-plugin/examples/deploy-ftp.html

Second point is a question about your project: is your WAR size normal?
I've heard of configurations that embedded superfluous jar in order to avoid the problem of META-INF/spring.handlers overwriting when building the final jar. If you're in this situation, you might be interested by this too:

http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html

这篇关于使用Spring和Maven时,将代码部署到服务器的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆