How to service JSPs or static resources outside the WAR/EAR in JBoss EAP 6/7

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Issue

  • There is an application that runs in EAP 4 and have the following configuration in jboss-web.deployer/server.xml. For example:
<Context path="/myapp/doc" appBase=""
		docBase="${jboss.server.home.dir}/resourceDir/doc"
		reloadable="true">
</Context>
<Context path="/myapp/pdf" appBase=""
		docBase="${jboss.server.home.dir}/resourceDir/pdf"
		reloadable="true">
</Context>
  • I see there is no option in web subsystem to map those directories as web resources. Those directories cannot be packaged in the application .war file, because the contents are produced by other application and just copied to "pdf" or "doc" directory. Also, they cannot be served from Apache WebServer, as there is some custom code from our .war file that loads or produces files in "doc" or "pdf" directories. So, how those directories can be mapped as static resources similarly as they are in EAP 4 ?
  • I saw some valve examples in jboss-web.xml but could not find similar conf for static resources. I see tomcat has this feature, but jbossweb restricts its usage.
  • Include external file location in web context? How to configure External context in server.xml on JBoss EAP6 ?
  • Migrating apps from WebSphere to EAP6, we need to replicate websphere's ability to mount external file locations into an application's web context.
  • Is there any methodology to make a static and dynamic files outside the EAR/WAR like extended document root functionality of WAS?
  • We need to display the information online in a folder that is not in JBoss ?

Resolution

  • To serve static contents outside the WAR,

    • The portable way is to write use a small Servlet which simply maps the request URL to a filesystem location and sends the content out. You can find examples from the references1 as shown below.
    • Or use the following JBoss specific (not portable) features
      • Creating symbolic links to outside your web application. See this article for details.
      • Specify outside directory to <overlay> in jboss-web.xml to add non-existing files to your deployment. An example setting as shown below2 adds files under /path/to/contents/ to your deployment.
        (Note that you can not replace files inside your deployment with specified <overlay> contents due to servlet spec. If same files exists inside deployment, it will be served. See also Content from issues.jboss.org is not included.JBWEB-279 about this.)
  • To load the files (like property files) outside the WAR, please create a module where you put your properties files then then add dependency to the module. See this article3 for details.

References:

```
<jboss-web version="7.0" 
        xmlns:jboss="http://www.jboss.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee jboss-web_7_0.xsd">
    ...
    <overlay>/path/to/contents/</overlay>
    ...
</jboss-web>
```
3

Where to put my application specific properties files outside WAR/EAR in JBoss EAP 6
https://access.redhat.com/site/solutions/186253

Root Cause

  • JBoss EAP 6.0.x (JBossWeb 7.0.x) handles static resources by the DefaultServlet. There are some options which can be configured with Content from docs.jboss.org is not included.static-resources setting inside web subsystem. However, there is no option to map the request URL to static resources location.
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.