How to change the path to the JCS cache cache file?

I am trying to change the path to the cache.ccf file for about an hour ...
When I call JCS.getInstance("myRegion"); I get this error:

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

I tried putting cache.ccf in the src folder. In this case, everything is fine. But I want it to be in the ./config/ directory, not in ./src . I tried changing the name of the configuration file:

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

But it does not work, and I get the same error:

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

This means that JCS is trying to find a file named "../config/cache.ccf" in the src directory.
Here I found this sentence:
The class path must include the directory in which the file is located, or the file must be placed at the root of the class path, as it is automatically detected.

But my application does not work, even if the cache.ccf file is in the root directory of the project.
How to change the path to the cache.ccf file?

+7
source share
4 answers

I had this problem - and because in my projects (for example, axis2, tomcat) there are several class loaders, it is quite difficult to determine where to put the cache.ccf file. I ended up not using the .properties file and not configuring it directly - this is 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"); 
+8
source

Turning to Jon, answer above. User code to load configuration from file. Put it before creating 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); } } 
+2
source

You can check your class path. It seems that only src is in the classpath folder, not in config. For me, I have * .ccf files placed in the configuration directory, which is in my class path, and I need to specify the path to the ccf file as / client _cache.ccf for JCS to pick it up.

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

+1
source

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); 
0
source

All Articles