2
votes

Trying to implement ehcache using ehcache.xml in wildfly10

Added ehcache.jar file as a module and added dependencies as mentioned below:

   <resources>
       <resource-root path="ehcache-1.2.2.jar"/> 
   </resources>

   <dependencies>
       <module name="org.apache.commons.logging"/>
       <module name="org.apache.log4j"/>
       <module name="javax.xml.parsers"/> 
   </dependencies>


</module>

I am getting following error when I try to run server war file.

Error configuring from d:\ehcache.xml. Initial cause was Error configuring from input stream. Initial cause was __redirected.__SAXParserFactory cannot be cast to javax.xml.parsers.SAXParserFactory

Any lead will be helpful.

StackTrace:

  • net.sf.ehcache.CacheException: Error configuring from
    d:\ehcache\ehcache.xml. Initial cause was Error configuring from
    input stream. Initial cause was __redirected.__SAXParserFactory
    cannot be cast to javax.xml.parsers.SAXParserFactory
    net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:80) net.sf.ehcache.CacheManager.parseConfiguration(CacheManager.java:752) net.sf.ehcache.CacheManager.init(CacheManager.java:386)
    net.sf.ehcache.CacheManager.(CacheManager.java:295)
    MySqlTest.ehcache(MySqlTest.java:93)
    MySqlTest.processRequest(MySqlTest.java:77)
    MySqlTest.doGet(MySqlTest.java:224)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77) io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50) io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284) io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263) io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81) io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174) io.undertow.server.Connectors.executeRootHandler(Connectors.java:202) io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) java.lang.Thread.run(Thread.java:745)
2
You need to make sure the path is in modules/javax/api/main/module.xml and then just add <module name="javax.api"/> as a dependency to your module. - Anup Dey
Hi, thanx for your comment, I tried that, but in vain, I will try it once again. - Namit Rana
Yes, this did the trick. - Namit Rana

2 Answers

2
votes

You seem to use Ehcache 1. This version is really really really old. You should at least upgrade to Ehcache 2. The latest is Ehcache 3. It is highly possible that Ehcache 1 isn't compatible with your current Java version and the wildfly dependencies.

1
votes

It worked with EhCache 3.3.1

  1. Put ehcache-3.3.1.jar file in wildfly10_HOME\modules\system\layers\base\org\ehcache\main

  2. Edit module.xml in the above folder as below

  3. Code:

String cacheName = "basicCacheNamit";

try (CacheManager cacheManager = newCacheManagerBuilder()
  .withCache(cacheName,
    newCacheConfigurationBuilder(Long.class, String.class, heap(100).offheap(1, MB)))
  .build(true)) {
  Cache<Long, String> basicCache = cacheManager.getCache(cacheName, Long.class, String.class);


  basicCache.put(1L, "da one!");
  String value = basicCache.get(1L);