使用嵌入式容器部署战争文件与可执行 jar 的建议 [英] Advice deploying war files vs executable jar with embedded container

查看:21
本文介绍了使用嵌入式容器部署战争文件与可执行 jar 的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 领域的当前趋势似乎是从以 war 文件(或ear 文件)的形式将Java Web 应用程序部署到Java servlet 容器(或应用程序服务器),而是将应用程序打包为带有嵌入式 servlet/HTTP 服务器(如 jetty)的可执行 jar.我的意思更重要的是,较新的框架正在影响新应用程序的开发和部署方式,而不是应用程序如何交付给最终用户(因为,例如,我明白为什么 Jenkins 使用嵌入式容器,非常容易获取和使用).采用可执行 jar 选项的框架示例:DropwizardSpring BootPlay(好吧,它不能在servlet 容器,但嵌入了 HTTP 服务器).

There seems to be a current trend in java space to move away from deploying java web applications to a java servlet container (or application server) in the form of a war file (or ear file) and instead package the application as an executable jar with an embedded servlet/HTTP server like jetty. And I mean this more so in the way newer frameworks are influencing how new applications are developed and deployed rather than how applications are delivered to end users (because, for example, I get why Jenkins uses an embedded container, very easy to grab and go). Examples of frameworks adopting the executable jar option: Dropwizard, Spring Boot, and Play (well it doesn't run on a servlet container but the HTTP server is embedded).

我的问题是,来自我们已经将我们的(到目前为止主要是 Struts2)应用程序部署到单个 tomcat 应用程序服务器的环境,如果我们计划使用嵌入式容器方法?目前,我们有大约 10 个自主开发的应用程序在单个 tomcat 服务器上运行,并且用于这些小型应用程序在一台服务器上共享资源和管理的能力很好.我们的应用程序不打算分发给最终用户以在他们的环境中运行.但是,如果我们决定利用更新的 Java 框架继续前进,这种方法是否应该改变?越来越多地使用云部署(例如 Heroku)是否会促使转向可执行 jars?

My question is, coming from an environment where we have deployed our (up to this point mostly Struts2) applications to a single tomcat application server, what changes, best practices, or considerations need to be made if we plan on using an embedded container approach? Currently, we have about 10 homegrown applications running on a single tomcat server and for these smallish applications the ability to share resources and be managed on one server is nice. Our applications are not intended to be distributed to end users to run within their environment. However, moving forward if we decide to leverage a newer java framework, should this approach change? Is the shift to executable jars spurred on by the increasing use of cloud deployments (e.g., Heroku)?

如果您有在单个应用服务器上以 Play 部署方式管理多个应用程序与传统 war 文件部署的经验,请分享您的见解.

If you've had experience managing multiple applications in the Play style of deployment versus traditional war file deployment on a single application server, please share your insight.

推荐答案

一个有趣的问题.这只是我对这个话题的看法,所以对所有事情持保留态度.我偶尔会使用 servlet 容器和嵌入式服务器来部署和管理应用程序.我确信使用 servlet 容器仍然有很多很好的理由,但我将尝试只关注为什么它们今天不那么受欢迎.

An interesting question. This is just my view on the topic, so take everything with a grain of salt. I have occasionally deployed and managed applications using both servlet containers and embedded servers. I'm sure there are still many good reasons for using servlet containers but I will try to just focus on why they are less popular today.

简短版本:Servlet 容器非常适合在单个主机上管理多个应用程序,但对于仅管理一个应用程序似乎不太有用.在云环境中,每个虚拟机一个应用程序似乎更可取,也更常见.现代框架希望与云兼容,因此转向嵌入式服务器.

Short version: Servlet containers are great to manage multiple applications on a single host but don't seem very useful to manage just one single application. With cloud environments, a single application per virtual machine seems preferable and more common. Modern frameworks want to be cloud compatible, therefore the shift to embedded servers.

所以我认为云服务是放弃servlet容器的主要原因.就像 servlet 容器让您管理应用程序一样,云服务让您管理虚拟机、实例、数据存储等等.这听起来更复杂,但在云环境中,已经转向单一应用程序机器.这意味着您通常可以将整台机器视为 应用程序.每个应用程序都在具有适当大小的机器上运行.云实例可以随时弹出和消失,这非常适合扩展.如果应用程序需要更多资源,您可以创建更多实例.

So I think cloud services are the main reason for abandoning servlet containers. Just like servlet containers let you manage applications, cloud services let you manage virtual machines, instances, data storage and much more. This sounds more complicated, but with cloud environments, there has been a shift to single app machines. This means you can often treat the whole machine like it is the application. Each application runs on a machine with appropriate size. Cloud instances can pop up and vanish at any time which is great for scaling. If an application needs more resources, you create more instances.

另一方面,专用服务器通常功能强大但大小固定,因此您可以在一台机器上运行多个应用程序以最大限度地利用资源.管理数十个应用程序——每个应用程序都有自己的配置、Web 服务器、路由和连接等——并不有趣,因此使用 servlet 容器可以帮助您保持一切可管理,并使您自己保持理智.但规模化更难.云中的 Servlet 容器似乎不是很有用.它们必须为每个微小的实例设置,没有提供太多价值,因为它们只管理一个应用程序.

Dedicated servers on the other hand usually are powerful but with a fixed size, so you run multiple applications on a single machine to maximize the use of resources. Managing dozens of application - each with their own configurations, web servers, routes and connections etc. - is not fun, so using a servlet container helps you to keep everything manageable and yourself sane. It is harder to scale though. Servlet containers in the cloud don't seem very useful. They would have to be set up for each tiny instance, without providing much value since they only manage a single application.

此外,云很酷,非云的东西很无聊(如果我们仍然相信炒作的话).默认情况下,许多框架都尝试具有可扩展性,以便可以轻松地将它们部署到云中.嵌入式服务器的部署和运行速度很快,因此它们似乎是一个合理的解决方案.Servlet 容器通常仍受支持,但需要更复杂的设置.

Also, clouds are cool and non-cloud stuff is boring (if we still believe the hype). Many frameworks try to be scalable by default, so that they can easily be deployed to the clouds. Embedded servers are fast to deploy and run so they seem like a reasonable solution. Servlet containers are usually still supported but require a more complicated set up.

其他几点:

  • 嵌入式服务器可以针对框架进行优化,或者更好地与框架工具(例如游戏控制台)集成.
  • 并非所有云环境都带有可自定义的机器映像.与编写初始化脚本来下载和设置 servlet 容器不同,使用专用软件进行云应用部署要简单得多.
  • 我还没有找到一个 Tomcat 设置,它不会在每次重新部署您的应用时出现 perm gen space 错误.当您几乎可以立即在暂存和生产实例之间切换而无需停机时,花更长的时间(重新)启动嵌入式服务器是没有问题的.
  • 正如问题中已经提到的,最终用户只需运行应用程序就非常方便.
  • 嵌入式服务器可移植且便于开发.今天,一切都快速,原型和 MVP 需要尽可能快地创建和交付.没有人愿意花太多时间为每个开发人员设置环境.
  • The embedded server could be optimized for the framework or is better integrated with the frameworks tooling (like the play console for example).
  • Not all cloud environments come with customizable machine images. Instead of writing initialization scripts to download and set up servlet containers, using dedicated software for cloud application deployments is much simpler.
  • I have yet to find a Tomcat setup that doesn't greet you with a perm gen space error every few redeployments of your app. Taking a bit longer to (re-)start embedded servers is no problem when you can almost instantly switch between staging and production instances without any downtime.
  • As already mentioned in the question, it's very convenient for the end user to just run the application.
  • Embedded servers are portable and convenient for development. Today everything is rapid, prototypes and MVPs need to be created and delivered as fast as possible. No one wants to spend too much time setting up an environment for every developer.

这篇关于使用嵌入式容器部署战争文件与可执行 jar 的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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