Hello everyone,

I would like to try to use Ehcache in one of my project, but at the moment
I'm having problem to create the CacheManager because it can't find the
ehcache.xml file.

My project is an EAR folder and it looks like that:

EAR/
--lib/library.jar (contains ehcache.xml and AbstractCacheService)
--ejb.jar (contains the @Singleton TestCache)

Here is the code:

public abstract class AbstractCacheService {
protected CacheManager manager = null;

public AbstractCacheService() {
manager = new CacheManager("ehcache.xml");
}

public void stopCacheManager() {
try {
manager.shutdown();
} catch (Exception e) {
log.error("Cache manager |{}| undeploymend error", getClass()
.getSimpleName(), e);
}
}
}

@Singleton
public class TestCache extends AbstractCacheService implements
TestCacheLocal {

private final Cache testCache;

/**
 * Constructor create the cache
 */
public TestCache() {
testCache = manager.getCache("testCache");
}
....
}

And I get the following error:
Caused by: java.io.FileNotFoundException: ehcache.xml (No such file or
directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at
net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:77)
at net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:670)
at net.sf.ehcache.CacheManager.init(CacheManager.java:366)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:282)
at
org.test.common.cache.AbstractCacheService.<init>(AbstractCacheService.java:27)

What is the best practice to make ehcache.xml available in the classpath? I
have tried /ehcache.xml /resource/ehcache.xml ... all with the same result.

Maybe the problem is due to the fact that ehcache.xml is in a jar stored in
the EAR/lib?

Thanks in advance
Luca

Reply via email to