Search code examples
javaspring-bootjboss

Static content not loading from spring boot war in jboss server


i have placed the static content such as css, js , images in static folder under resources and all the html files in templates folder. however when i build a war and deploy it on jboss. the html is loaded but static content is not loaded and the same works fine in inbuild tomcat server.

url to access the war pages : IP:8080/warname/login when i inspect in console of chrome i get url of js, css as IP:8080/js/jsfile.js or IP:8080/css/abc.css.

here is my project structure image of project structure

Here is how i am using css,js in html files


Solution

  • You are referencing the static content in src or href with for example /js but this does not work when deploying as WAR file because in the app server there will be a context root added. (warname in your case)

    You have to use Thymleaf syntax like

    <script type="text/javascript" th:src="@{/js/searchOP.js}"></script>
    

    Please checkout the documentation for more information: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html