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

て烟熏妆下的殇ゞ 提交于 2019-11-28 09:14:09

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:

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">

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/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!