How to change JCS cache.ccf file's path?

shift66 picture shift66 · May 24, 2012 · Viewed 8.4k times · Source

I'm trying to change path of cache.ccf file about an hour...
When I'm calling JCS.getInstance("myRegion"); I'm getting this error:

Exception in thread "main" java.lang.IllegalStateException: Failed to load properties for name [/cache.ccf]

I tried to put cache.ccf into src folder. In this case everything's OK. But I want it to be in ./config/ directory, not in ./src. I tried to change config file name:

JCS.setConfigFilename("../config/cache.ccf");

But it's not working and I'm getting the same error:

Exception in thread "main" java.lang.IllegalStateException: Failed to load properties for name [../config/cache.ccf]

It seams that JCS tries to find the file named "../config/cache.ccf" in src directory.
Here i found this sentence:
The classpath should include the directory where this file is located or the file should be placed at the root of the classpath, since it is discovered automatically.

But my applilcation don't work even if cache.ccf file is in the root directory of project.
How can I change cache.ccf file's path?

Answer

Jon picture Jon · Oct 24, 2012

I've had this problem - and because there's multiple class loaders around in my projects (axis2, tomcat), it can be pretty hard to figure out where to put the cache.ccf file. I ended up not using a .properties file and configuring it directly - here's how I did it...

CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
Properties props = new Properties();

props.put("jcs.default","DC");
props.put("jcs.default.cacheattributes",
          "org.apache.jcs.engine.CompositeCacheAttributes");
// lots more props.put - this is basically the contents of cache.ccf

ccm.configure(props);
JCS sessionCache = JCS.getInstance("bbSessionCache");