I have a web application deployed as a WAR file in Tomcat 7. The application is build as a multi-module project:
Normally, we can put our JSP files in the webapp project, and reference them relative to the context:
/WEB-INF/jsp/someMagicalPage.jsp
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()
.
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.
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...
Servlet 3.0 which Tomcat 7 supports includes the ability to package jsps into a jar.
You need to:
META-INF/resources
directory of your jarweb-fragment.xml
in the META-INF
directory of your jarWEB-INF/lib
directory of your warYou 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