i want to use same ehcache.xml for different projects

i want to use same ehcache.xml for different projects

Where i put the ehcache.xml common for two projects

please help me
Manikandan ThiagarajanSenior consultantAsked:
Who is Participating?
mrcoffee365Connect With a Mentor Commented:
Do you mean that code works within one project?

In that case, it's probably the "localhost" part.  You have to have ea way to identify the 2 different projects in your web server.  Can you use a url in a browser to get the xml file?  If not, then you don't have a correct configuration.

In my experience, it usually works better not to use "localhost" but to have a real domain name.  If you are developing on a machine without a public host name for your server, then you put the alias in your hosts file.

Work on being able to get the xml file from a browser and that will give you a url which works for projecta and projectb.
mrcoffee365Connect With a Mentor Commented:
There's no magic answer.  You'll have to pick a place you think is reasonable for both projects.  If they are usually installed together, you could have one of them read from the location of the other project.  For example, put your xml file in the WEB-INF directory of ProjectA and have ProjectB read from ProjectA's xml file location.

Or pick a separate location.  There are problems with all of these.  Some people create a program invoked at install time to check if the required xml file exists in a reasonable location, and configures the new project to use the existing file.  That's more work, and usually means you can't rely solely on a war installation (if you are doing that).

So as you might expect, the solution is really up to you.  No magic.
Manikandan ThiagarajanSenior consultantAuthor Commented:
package com.sm;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Ehcache;
* A simple example Java client which uses the built-in java.net.URLConnection.
* @author BryantR
* @author Greg Luck
public class ehCacheClientParentCall{
private static String TABLE_COLUMN_BASE =
private static String TABLE_COLUMN_ELEMENT =
private static Ehcache widgetCache;
* Creates a new instance of EHCacheREST
public ehCacheClientParentCall() {
public static void main(String[] args) {
       CacheManager manager = new CacheManager(TABLE_COLUMN_BASE);
        widgetCache = manager.getEhcache( "widgets" );
i have error when i pick other project
Manikandan ThiagarajanSenior consultantAuthor Commented:
the error is

Exception in thread "main" net.sf.ehcache.CacheException: Error configuring from http:\localhost:8080\Parent\ehcache.xml. Initial cause was http:\localhost:8080\Parent\ehcache.xml (The filename, directory name, or volume label syntax is incorrect)
      at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:77)
      at net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:273)
      at net.sf.ehcache.CacheManager.init(CacheManager.java:231)
      at net.sf.ehcache.CacheManager.<init>(CacheManager.java:169)
      at com.sm.ehCacheClientParentCall.main(ehCacheClientParentCall.java:28)
Caused by: java.io.FileNotFoundException: http:\localhost:8080\Parent\ehcache.xml (The filename, directory name, or volume label syntax is incorrect)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(FileInputStream.java:120)
      at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:74)
      ... 4 more
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.