是否可以从lib的JAR内部提供JSP,还是有解决方法? [英] Can I serve JSPs from inside a JAR in lib, or is there a workaround?

查看:86
本文介绍了是否可以从lib的JAR内部提供JSP,还是有解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Tomcat 7中将一个Web应用程序部署为WAR文件.该应用程序被构建为一个多模块项目:

I have a web application deployed as a WAR file in Tomcat 7. The application is build as a multi-module project:

  • 核心-打包为JAR,包含大多数后端代码
  • core-api-打包为JAR,包含指向core的接口
  • webapp-打包为WAR,包含前端代码并且取决于核心
  • customer-extensions-可选模块,打包为JAR

通常,我们可以将JSP文件放入webapp项目中,并相对于上下文引用它们:

Normally, we can put our JSP files in the webapp project, and reference them relative to the context:

/WEB-INF/jsp/someMagicalPage.jsp

问题是我们如何处理特定于客户扩展项目的JSP文件,这些文件不应始终包含在WAR中.不幸的是,它似乎无法在JAR文件中引用JSP.尝试classpath:jsp/customerMagicalPage.jsp会导致在JspServlet中找不到该文件,因为它使用的是ServletContext.getResource().

The question is what we do about JSP files that are specific to the customer-extensions project, that should not always be included in the WAR. Unfortunately, I cannot refer to JSPs inside JAR files, it appears. Attempting classpath:jsp/customerMagicalPage.jsp results in a file not found in the JspServlet, since it uses ServletContext.getResource().

传统上,我们解决"了让maven解压缩客户扩展JAR,定位JSP并在构建之时将它们放入WAR中的问题.但是理想的情况是,您只需在Tomcat中爆炸的WAR中放入一个JAR,然后发现该扩展名-该扩展名除了JSP以外都适用.

Traditionally, we "solved" this having maven unpack the customer-extensions JAR, locate the JSPs, and put them in the WAR when building it. But an ideal situation is where you just drop a JAR in the exploded WAR in Tomcat and the extension is discovered - which works for everything but the JSPs.

总有办法解决吗?标准方法,特定于Tomcat的方法,hack或解决方法?例如,我一直在考虑在应用程序启动时解压缩JSP ...

Is there anyway to solve this? A standard way, a Tomcat-specific way, a hack, or a workaround? For example, I've been thinking of unpacking the JSPs on application startup...

推荐答案

Tomcat 7支持的Servlet 3.0具有将jsps打包到jar中的功能.

Servlet 3.0 which Tomcat 7 supports includes the ability to package jsps into a jar.

您需要:

  • 将jsps放在jar的META-INF/resources目录中
  • (可选)在jar的META-INF目录中包含一个web-fragment.xml
  • 将罐子放在战争的WEB-INF/lib目录中
  • place your jsps in META-INF/resources directory of your jar
  • optionally include a web-fragment.xml in the META-INF directory of your jar
  • place the jar in WEB-INF/lib directory of your war

然后,您应该能够在您的上下文中引用您的jsps.例如,如果您有一个jsp META-INF/resources/test.jsp,则应该可以在上下文的根目录将其引用为test.jsp

You should then be able to reference your jsps in your context. For example if you have a jsp META-INF/resources/test.jsp you should be able reference this at the root of your context as test.jsp

这篇关于是否可以从lib的JAR内部提供JSP,还是有解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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