Search code examples
javascripthtmljbosswildflyjboss7.x

Problem pubishing in JBOSS, links to files (images, subpages) HTML with aboslute path redirect to / instead APP


I got an EAR file, I try to deploy and It deploys fine, without error. The problem is the following:

All the ccs files, images, files, etc are using absolute paths in the HTML files, (the HTML files are being generated through an external program so change to relative paths is not an option), so the styles are not being loaded, the links to other pages don't work, etc.

An example to clarity:

I have the ear deployed in "localhost:8080/app, the index.html file loads but inside the file, I try to use the link to the page2.html, and the path is localhost:8080/page2.html instead "localhost:8080/app/page2.html".

The browser says "the page cannot be loaded"

How can I fix this without change the paths to relative? I have the context root of application.xml with "app" and the welcome file of web.xml inside the war file with "index.html".

the structure is the following:

file.ear meta-inf file.war web-inf index.html css folder pageX.html

I beg for help.

Thanks in advance.


Solution

  • First you need to know understand, how file system works in web.

    <link rel="stylesheet" href="slick.css"> // file present in same folder
    <link rel="stylesheet" href="css/slick-theme.css"> // file present in css folder of current folder
    <link rel="stylesheet" href="/css/slick-theme.css"> // file present in the css folder at the root directory of the current web
    <link rel="stylesheet" href="../slick-theme.css"> // file present at one level up the current folder
    

    Since all your files path starts with /, server tries to find it relative to the root directory.

    All you need is to deploy your app as root app without any context-root.

    This will require 2 things:

    1)

    <context-root>/</context-root>
    

    2) configuration change at server level, remove default content mapping, try to find

    <location name="/" handler="welcome-content"/>
    

    (may vary in your jboss version) and comment it.

    Attaching screenshot of your working app: enter image description here

    PS: Delete your EAR from repo or make it private