java - Tomcat 8 new Resource implementation to map Jar files in a separate directory -


with tomcat 8 have extend webappclassloader , add jar filed shared location classloader path using addrepository() method. tomcat 8 addrepository have been removed , new resource implementation have been introduced. i'm still able use addurl method add jar files. implement new resource based implementation.

i've tried with

dirresourceset dirresourceset = new dirresourceset(getcontext().getresources(), "/web-inf/lib", "/home/thusitha/lib/runtimes/cxf", "/"); webresourceroot webresourceroot = getcontext().getresources(); webresourceroot.getcontext().getresources().addpreresources(dirresourceset); 

but not working , still throws classnotfoundexception

can tell me how map directory contains jars particular webapp using tomcat new resource implementation?

a solution problem register resources overriding contextconfig class (org.apache.catalina.startup.contextconfig). catalina enters starting state after scans document path resources. of processing of resources, such annotations, handled contextconfig lifecyclelistener. ensure resources added before context configuration takes place, override contextconfig.

    final context currentcontext = ctx;      contextconfig ctxcfg = new contextconfig() {         @override         public void lifecycleevent(lifecycleevent event) {             if (event.gettype().equals(lifecycle.configure_start_event)) {                  webresourceroot webresourcesroot = currentcontext.getresources();                  string basedir = platform.getbasedir(); // server base directory                  file libdir = new file(basedir + file.separator + "lib");                  dirresourceset dirresourceset = null;                 try {                     dirresourceset = new dirresourceset(webresourcesroot, "/web-inf/lib", libdir.getcanonicalpath(), "/");                 } catch (ioexception e) {                     throw new runtimeexception(e);                 }                  webresourcesroot.addpostresources(dirresourceset);                  string[] possiblejars = dirresourceset.list("/web-inf/lib");                  for(string libfile : possiblejars) {                     webresource possiblejar = dirresourceset.getresource("/web-inf/lib/"+libfile);                     system.err.println(string.format("loading possible jar %s",possiblejar.getcanonicalpath())); // checking...                     if (possiblejar.isfile() && possiblejar.getname().endswith(".jar")) {                         webresourceset resourceset = new jarresourceset(webresourcesroot, "/web-inf/classes", possiblejar.getcanonicalpath(),"/");                         webresourcesroot.addpostresources(resourceset);                     }                 }             }              super.lifecycleevent(event);         }     };      ctx.addlifecyclelistener(ctxcfg); 

this undocumented solution works on tomcat 8.0.23. considering complexity , difficulty of can't better solution adding jars directly classloaders.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -