user2076397
user2076397

Reputation: 43

Resources shared by two projects in java

I have two projects that share some resources, some of these resources are images, property files ... I wonder how I can get the two projects to access these resources without duplicating them.

I am working with the eclipse IDE, I just want to refer to them to avoid duplication.

The projects are two web applications, my only development framework is JSF.

Upvotes: 0

Views: 116

Answers (2)

Alex Dutescu
Alex Dutescu

Reputation: 96

By default, the resource handling mechanism introduced in JSF 2.0 looks up resource in the following locations:

In /resources under the web application root folder.
In /META-INF/resources in JAR files.

You can set another resource folder inside your context root (wich by way is inside your project and you can't point to an external resource) by adding

<context-param>
  <param-name>
    javax.faces.WEBAPP_RESOURCES_DIRECTORY
  </param-name>
  <param-value>/path/to/resource</param-value>
</context-param>

to your web.xml, but i wrote this only for educational purpouses because you can't leave the scope of your app folder.

So your only viable option is to "cook" your own jar with your images and property files added in /META-INF/resources. Then add your jar as an external jar to your project and you are good to go.

Upvotes: 1

Chris Hinshaw
Chris Hinshaw

Reputation: 7255

IMHO you should use Maven, this is what I use to manage projects dependencies. You would either need to put the resources into one of the projects or create a separate project (jar) that both can share.

Upvotes: 0

Related Questions