문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top