2

I'm trying to make my application works with WebJars running on Tomcat7 but the CSS/JS files aren't found by my HTML pages.

I already change the web.xml to v3.0 and the facets of the project too (inside Eclipse). Also checked the web.xml from tge container and that's already configured as v3.0 too.

As I'm using SpringMVC, I made the configuration described into the official documentation:

<resources mapping="/webjars/**"    location="classpath:/META-INF/resources/webjars/"/>

Inside my "sitemesh3.xml" file, I already configured an exclusion to the folder "resources":

<?xml version="1.0" encoding="UTF-8"?>

<sitemesh>
    <mapping path="/*" decorator="/resources/decorator.html"/>
    <mapping path="/resources/*" exclue="true"/>

    <content-processor>
        <tag-rule-bundle class="org.sitemesh.content.tagrules.html.DivExtractingTagRuleBundle" />
    </content-processor>
</sitemesh>

Inside my "decotator.html" file I'm trying to access the JS by this way:

<script src="/webjars/select2/select2.js"></script>

or

<script src="../webjars/select2/select2.js"></script>

Inside my "pom.xml" file correctly added the dependency:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>select2</artifactId>
    <version>3.4.5</version>
</dependency>

To me it looks like the Tomcat7 is deploying the application as servlet version 2.5, once that the files inside the select2.jar aren't being public exposed.

Does someone know if I need to configure something more? Can you see anything wrong?

Kriem
  • 8,666
  • 16
  • 72
  • 120
Pmt
  • 1,122
  • 3
  • 13
  • 27
  • Most likely the issue is you are not including the context in the URL path. It's usually the name of your WAR file, minus the ".war" part. You can get the URL, including the proper context, but using the Spring `` tag. Javadoc for the tag: http://docs.spring.io/spring/docs/3.0.x/api/org/springframework/web/servlet/tags/UrlTag.html – CodeChimp Mar 26 '14 at 19:56
  • @CodeChimp, I don't think this is the problem. Take a look at the URL where the file isn't found: http://localhost:8080/myproject/webjars/select2/select2.js What do you think? – Pmt Mar 26 '14 at 21:57
  • Can you try a few things? First, I think Spring will log the mappings it has upon bootup. It may require you to turn on debug for 'org.springframework.http' and 'org.springframework.web'. I would also try to hit the URL without the 'webjar' in there. Just do `localhose:8080/myproject/select2/select2.js`. – CodeChimp Mar 27 '14 at 11:03

1 Answers1

2

Two possible ideas:

There is a typo:

<mapping path="/resources/*" exclue="true"/>

Should probably be exclude not exclue.

Maybe your sitemesh3.xml exclusion to be:

<mapping path="/webjars/*" exclude="true"/>
James Ward
  • 29,283
  • 9
  • 49
  • 85