Search code examples
javajbossjboss7.xjboss-eap-6staticresource

How to make a local JBOSS AS 7 serve static resources?


As a standard, my static resources need to stay in a centralized location, out of my EARs / WARs (so that they can be updated without rolling out a new release for minor JS/CSS changes).

My HTML imports are relative, eg:

<script type="text/javascript" src="/resources/myApp/js/bootstrap.min.js"></script>

This means that the URLs to resources are different on every server (development, test, production..):

On dev-foobar.com:

dev-foobar.com/resources/myApp/js/bootstrap.min.js

On tst-foobar.com:

tst-foobar.com/resources/myApp/js/bootstrap.min.js

On foobar.com:

foobar.com/resources/myApp/js/bootstrap.min.js


But when I'm on my LOCAL Jboss (localhost:8080), how can I instruct it to serve the same static resources to achieve the following URL ?

localhost:8080/resources/myApp/js/bootstrap.min.js


Solution

  • JBoss handles all the static resources through a folder called welcome-content under $JBOSS_HOME:

    C:\Program Files\EAP-6.2.0\jboss-eap-6.2\welcome-content

    Simply put something there, and it will be exposed in the root context.

    For example, it's sufficient to copy the sample folders and file described in the question:

    C:\Program Files\EAP-6.2.0\jboss-eap-6.2\welcome-content\resources\myApp\js\bootstrap.min.js

    to end with the file (but not the folders) being accessible through the URL:

    localhost:8080/resources/myApp/js/bootstrap.min.js

    Well done, Red Hat !