4

Is there a way to return JavaScript that is located in a .jar archive? At the moment I have the following structure:

webapp
   resources
        scripts
           SomeJavaScript.js
           ...

List of such .js files is very large. And there is a .jar file that has all such files.

In Spring config files I have:

  <mvc:resources mapping="/resources/**" location="/resources/"/>

To process all static resources by my dispatcher servlet. But, I'd like it to read the JavaScript files from the .jar archive. What's the easiest way to do that?

I think writing my own controller for such purpose would not be the best option.

PS: I've found the following solution:

I'm using embedded Tomcat 7, starting it using Maven plugin. Here's mentioned that resource files need to be under WEB-INF/lib/{\*.jar}/META-INF/resources but looking inside spring-js-resources.jar, the actual location is WEB-INF/lib/{\*.jar}/META-INF/web-resources. The generated page contains links like these:

<script type="text/javascript" src="/SomeProjectName/dojo/dojo.js"></script>

And this file is not available. What can I do to resolve the problem?

Thanks.

Community
  • 1
  • 1
Alexandr
  • 9,213
  • 12
  • 62
  • 102

1 Answers1

5

You can use the mvc:resources tag to expose contents of .jar files on the classpath by adding a classpath: path to the locations attribute.

I believe in your case it would be something like

 <mvc:resources mapping="/resources/**" location="/resources/, classpath:/META-INF/web-resources/"/>

More information in Spring MVC documentation.

kryger
  • 12,906
  • 8
  • 44
  • 65
  • I've read the documentation, and I agree with you, that it should help, but it doesn't. Also, I deployed war file into the tomcat 7 webapps (not embeddable one) but it did not help either. – Alexandr Apr 24 '13 at 07:24
  • Actually it helped! I've forgotten to update my url in jsp pages. I set it as: and it helped!!!! Thank you very much for your reply. I'm really tired to fight with spring, maven, etc and its configuration. Not development. Only configuration wars:( – Alexandr Apr 24 '13 at 07:38
  • Yeah, I agree path-related problems are one of the most frustrating; perhaps setting Spring's logging level to DEBUG/TRACE would help? It usually prints all tried locations one by one. – kryger Apr 24 '13 at 09:23