java 从 Web 应用程序 (Tomcat7) 中的 jar 文件公开资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4732965/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 07:46:19  来源:igfitidea点击:

Exposing resources from jar files in web applications (Tomcat7)

javatomcatservletstomcat7

提问by Igor Mukhin

Some time ago I read an article what is expected to be in Servlet API 3.0. I remember I read that you can save some .jsp files in a /WEB-INF/lib/somelib.jar/META-INF/web/.jsp and this resources will be exposed to the context root of the web application.

前段时间我读了一篇文章 Servlet API 3.0 中的预期内容。我记得我读过您可以将一些.jsp 文件保存在 /WEB-INF/lib/somelib.jar/META-INF/web/.jsp 中,并且这些资源将暴露给 Web 应用程序的上下文根。

I have just installed Tomcat7 to give it a try, but I found no documentation that I can put some web-resources in jar-files.

我刚刚安装了 Tomcat7 来试一试,但我没有发现可以将一些网络资源放在 jar 文件中的文档。

  • Does this feature exists in servlet api 3.0?
  • Does this feature exists in tomcat 7.0?
  • Is there another way to have jsp-files in /lib/*.jar files?
  • servlet api 3.0 中是否存在此功能?
  • 这个功能在 tomcat 7.0 中存在吗?
  • 有没有另一种方法可以在 /lib/*.jar 文件中包含 jsp 文件?

回答by Chuk Lee

There is a feature in servlet 3.0 that allows you to package resources (images, jsp, etc.) in a JAR file. What you do is in your jar file, you create META-INF/resourcesand dump anything you want in there including directories for structuring your resources. What happens is that META-INF/resourceswill be mapped to the docrootof your web application.

servlet 3.0 中有一个特性允许您将资源(图像、jsp 等)打包到 JAR 文件中。您所做的是在您的 jar 文件中,您可以META-INF/resources在其中创建和转储任何您想要的内容,包括用于构建资源的目录。发生的事情是META-INF/resources将映射到docroot您的 Web 应用程序的 。

When there is a clash of resource between your app and the JAR file, your apps resource will be returned. See this

当您的应用程序和 JAR 文件之间存在资源冲突时,您的应用程序资源将被返回。看到这个

Tomcat 7 supports Servlet 3 so it should support this feature

Tomcat 7 支持 Servlet 3 所以它应该支持这个特性