Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

caching

jcs

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?

like image 561
shift66 Avatar asked May 24 '12 08:05

shift66


3 Answers

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");
like image 107
Jon Avatar answered Nov 01 '22 08:11

Jon


Expanding on Jon's answer above. Custom code to load config from file. Put it before instantiating JCS.

    final String configFilename = System.getProperty("jcs.configurationFile");

    if (configFilename != null)
    {
        try (FileReader f = new FileReader(configFilename))
        {
            Properties props = new Properties();
            props.load(f);
            CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
            ccm.configure(props);       
        }
    }
like image 37
Nazar Avatar answered Nov 01 '22 08:11

Nazar


You may want to check your classpath. Seems like only src is in the classpath and not config folder. For me I have my *.ccf files placed in config directory which is in my classpath and I need only to specify the path to the ccf file as /client_cache.ccf for JCS to pick it up.

It also depends on your deployment environment. However if you have /config listed in your classpath it should work.

like image 26
Keshi Avatar answered Nov 01 '22 08:11

Keshi