Return JavaScript as a static resource from the Jar archive

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

webapp resources scripts SomeJavaScript.js ... 

The list of such .js files is very long. And there is a .jar file that has all such files.

In Spring configuration files, I have:

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

Handling all static resources with my dispatch servlet. But I would like him to read JavaScript files from the .jar archive. What is the easiest way to do this?

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

PS: I found the following solution :

I am using the built-in Tomcat 7, starting it with the Maven plugin. It is mentioned here that the resource files must 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 the following links:

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

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

Thanks.

+4
source share
1 answer

You can use the mvc:resources tag to display the contents of .jar files in the class path by adding the classpath: path to the locations attribute.

I believe in your case that it will be something like

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

More information in Spring MVC Documentation .

+5
source

All Articles