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.
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.