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

孤者浪人 提交于 2019-12-23 07:57:41

问题


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?


回答1:


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



回答2:


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);       
        }
    }



回答3:


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.




回答4:


I found this relevant information

https://commons.apache.org/proper/commons-jcs/faq.html#configuration-file

CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance(); 
Properties props = new Properties(); 
props.load(/* load properties from some location defined by your app */); 
ccm.configure(props);


来源:https://stackoverflow.com/questions/10733681/how-to-change-jcs-cache-ccf-files-path

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