spring-bootjawr

Spring boot with jawr not working


I am trying to integrate Spring boot with jawr, but getting below error:

n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/dependency.css n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/app.css n.j.w.r.b.r.AbstractBundleLinkRenderer : No bundle found for path : /bundles/ie-support.js

I have these files present in my static folder:

Folder structure of my project

What is happening?

my index.ftl file.

enter image description here


Solution

  • Did you check to see if your bundles are being generated in your temp directory. Example in windows you would find the temp directory usually under:

    C:\Users\<username>\AppData\Local\Temp\tomcat.<random numbers>.8080\work\Tomcat\localhost\<context path>\jawrTmp
    

    What I found was that because its a jar your building and not the old mvc war files with the webapp directory you need to use the classpath generator:

    https://j-a-w-r.github.io/docs/generators.html

    The prefix is a key you will specify when implementing the Generator, and the path is a string which will have different meaning depending on your generator’s functionality. Also, you have params in parentheses and in brackets (both of which are optional), that further help in parameterizing the mappings. A simple mapping example, with no params, is as follows:

    jawr.js.bundle.one.mappings=jar:net/jawr/cpscript.js
    

    Be careful though because I myself personally did not notice this nugget:

    Unlike the normal mapping, this way of referring to resources does not yet allow wildcards (i.e.: jar:/com/mycompany/myapp/** would not work).

    Since it won't recursively go through the directories I had to manually add all of them to the jawr.properties.

    Some Additional Information

    After this I noticed that the the .sorting files would be appended to the content of the bundle (and for some funny reason I couldn't figure out why some of the mappings would double up with /jar:<mapping>; which the MinJS processor to completally lose its mind.

    So I personally couldn't find a way around this so I built a custom PostProcessor and PreProcessor. The PreProcessor goes through each of the mappings and fixed the /jar:<mapping> value to jar:<mapping> and populates a static list wit the contents of the .sorting file.

    The PostProcessor than removes from the content of the bundle any reference to the values contained in that static list (well that solved that problem). Still having a problem where I can http to the bundle with a prefix of context-path/jsb/bundles but my applications are not picking up still /bundles so not sure if I myself had the problem.

    In short because you have a jar you have to load the content over classpath and not over the servlet (which by default its searching for i believe.)

    Hope this helps, if you do manage to get it all functioning please share here as there is very little documentation with spring-boot jars and jawr.