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

后端 未结 2 682
慢半拍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

    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
    
    0 讨论(0)
  • 2020-12-09 20:40

    You might want to take a look at this blog post. It covers a method for sharing resources using maven:

    http://www.sonatype.com/people/2008/04/how-to-share-resources-across-projects-in-maven/

    0 讨论(0)
提交回复
热议问题