开发者

Why packaging JAR files into WAR archive if they are available in Maven Central?

开发者 https://www.devze.com 2023-04-13 03:39 出处:网络
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-

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号