如果 JAR 文件在 Maven Central 中可用,为什么要将它们打包到 WAR 存档中?

发布于 2024-12-10 17:51:54 字数 131 浏览 0 评论 0原文

我想知道是否可以以某种方式通知 Servlet 容器在部署期间从 Maven Central 下载所需的 JAR 存档,而不是将它们打包到 WAR 中(在 WEB-INF/lib 中)。据我了解,Java 的设计就是考虑到了这种方法。技术上可行吗?

I wonder whether it's possible somehow to inform Servlet Container to download required JAR archives from Maven Central during deployment, instead of packaging them into WAR (in WEB-INF/lib). As far as I understand Java is designed with such an approach in mind. Is it technically possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空‖城人不在 2024-12-17 17:51:54

我不知道有任何 servlet 容器可以执行此操作。 Servlet 规范规定 WAR 文件将包含应用程序的所有依赖项。当然,任何事情“技术上都是可能的”,这是一个有趣的想法,但我认为你会做很多自定义编码。我认为唯一能与之相近的是 Virgo Web Server。它是一个 OSGi/Spring DM 容器,它的概念是 一个“存储库”,可以在其中找到工件并按需加载。它可以是 配置为使用本地 Maven 存储库。如果还没有选择的话,使其使用远程存储库应该是一个相对较短的步骤。 Virgo 允许将 WAR 以及 OSGi 包部署到其中,但它不是典型的 servlet 容器。

I'm not aware of any servlet container that does this. The servlet spec says that a WAR file will contain all the dependencies for the app. Of course, anything is "technically possible", and it's an interesting idea, but I think you'd be doing a lot of custom coding. The only thing I think of that's even remotely close is Virgo Web Server. It's an OSGi/Spring DM container, and it has a concept of a "repository" where artifacts can be found and loaded on demand. It can be configured to use a local Maven repo. It should be a relatively short step to make it use a remote repo, if that isn't already an option. Virgo allows WARs to be deployed to it as well as OSGi bundles, but it isn't a typical servlet container.

黎歌 2024-12-17 17:51:54

Servlet 规范出现在 Maven 之前。这就是为什么 war 文件应该包含 jar 的原因。

如果你问为什么他们不改变这一点:两个原因:

  • 它将打破现有的习惯和现有的 servlet 容器
  • maven 不是标准 - 标准不能依赖非标准(即使它是事实上的标准) )

如果你问这是否可能并且是个好主意。这是可能的,但这可能不是一个好主意。您应该部署已经测试过的东西(在分阶段和/或 QA 环境中)。您无法确认存储库中的依赖项不会被替换,因为您无法确定在部署期间与存储库的连接是否正常,这将破坏您的部署。

The servlet spec comes before maven. That's why the war files should contain the jars.

If you are asking why they don't change that: two reasons:

  • it will break existing habits and existing servlet containers
  • maven is not a standard - a standard can't rely on non-standard (even though it is a de-facto standard)

If you are asking if it is possible and a good idea. It is possible, but it may not be a good idea. You should deploy something that is already tested (on a staged and/or QA environment). You can't confirm that the dependency in the repo won't be replaced, as you can't be sure that the connectivity to the repository will be OK during deployment, which will break your deployment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文