Announcement Announcement Module
No announcement yet.
Return JS files from jar arhive Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Return JS files from jar arhive


    I'll try to explain better.

    With Servlet API-3 specification (it is supported by Tomcat 7) there is a way to store all web resources file in one jar file.
    Especially it is usefull when you use JavaScript framework that itself depends on other JavaScript files.
    As a result you don't have to store all such files under the webapp/resources folder. You just save them into one jar file. Save them into META-INF/resources folder of the jar itself, deploy jar into the webapp/WEB-INF/lib.

    When html page is returned to the user, all such files are visible on html page.
    For example I need myJavaScript.js file, that is saved in myJar.jar file, and its path inside jar is META-INF/resources/myJavaScript.js. I save myJar.jar file inside of WEB-INF/lib folder.

    Now, when I refer to myJavaScript.js inside html page header it should be visible.
    Instead of myJar.jar I use spring webflow - spring-js-resources.jar file. I need access to its META-INF/web-resoures/spring/Spring.js file. In by html page header I refer it as:
    <script type="text/javascript" src="spring/Spring.js"> <!----></script>

    But the file is not availble. So my first question why? By the way, I'm starting tomcat as embeddable with maven tomcat plugin. Maybe it is the reason of the problem.

    My second question, why all files inside spring-js-resources.jar files are located under WEB-INF/web-resources, but not under WEB-INF/resourses folder as it should to be.

    EDIT: to solve it I tried to use:
    <mvc:resources mapping="/resources/**" location="/resources/, classpath:/META-INF/web-resources/" />
    But it did not help me either.

    My third question, it became available only in Servlet API-3. Probably there is an alternative way to use jar files for such purpose.

    Solved!!!!!! with edited mvn:resources mapping I also have to update my jsp links, adding "resources" into the value:
    <spring:url value="/resources/spring/Spring.js" var="springJs"/>
    <script type="text/javascript" src="${springJs}"> <!----></script>

    It resolved now!!!!))
    Last edited by savswsoft; Apr 24th, 2013, 02:35 AM.