jawr configuration location settings in JBoss 4.0 and 4.2

I use jawr in my current project. jawr is a Java library for bundling and compressing JavaScript and CSS files.

The original jawr servlet configuration (taken from the online documentation) was working fine in Weblogic 10 and in JBoss 4.0.5 GA:

<servlet>
    <servlet-name>JavascriptServlet</servlet-name>
    <servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
    <init-param>
        <param-name>configLocation</param-name>
        <param-value>/jawr.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

After switching to JBoss 4.2.2 GA, I was getting a NullPointerException when the JawrServlet was starting. Lines 56 and 57 from the PropsFilePropertiesSource class were causing the exception:

URL url = Thread.currentThread().getContextClassLoader().getResource(configLocation);
InputStream is = new FileInputStream(new File(url.getFile()));

The cause to this exception is the classloader of JBoss, which doesn’t resolve the root to the WEB-INF/classes or WEB-INF/lib. The solution is easy – remove the leading slash from location of the jawr configuration file in the jawr servlet configuration:

<servlet>
    <servlet-name>JavascriptServlet</servlet-name>
    <servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
    <init-param>
        <param-name>configLocation</param-name>
        <param-value>jawr.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
Advertisements