How to manage shared resources for several web apps in Maven AND Eclipse?

后端 未结 2 705
慢半拍i
慢半拍i 2020-12-09 20:10

Note: I didn\'t get any response in the first version of this question, so I modified it to be more generic...

Context

My project i

2条回答
  •  天命终不由人
    2020-12-09 20:22

    Starting with Servlet 3.0, you can share resources by putting them within the src/main/resources/META-INF/resources directory.

    When the webapp deploys, Servlet 3.0 makes those resources available from the context path. For example, in your case...

    web-resources
    -- src
    ---- main
    ------ resources
    -------- META-INF
    ---------- resources
    ------------ css
    -------------- global.css
    ------------ images
    -------------- background.png
    

    Let's assume that my_project has a dependency on web-resources and is deployed to the url http://my.localhost:8080/myProject.

    With that configuration, the following URLs will resolve to the correct resources:

    • http://my.localhost:8080/myProject/css/global.css
    • http://my.localhost:8080/myProject/images/background.png

    IF you have a name conflict between the resources and your actual application, the application will win.

    Be sure your web.xml states you are using Servlet 3.0

    
    

提交回复
热议问题