java - Starting a WebAppContext in isolation -
java - Starting a WebAppContext in isolation -
i trying start jetty server web context. web.xml
passing contains custom class (for different reasons) on classpath of code executing code below. expect jetty not able find class specified in web.xml
, does.
how build new server
webappcontext
not load classes current context?
the code below in scala, should give thought have tried. if reply java fine.
// reference root class loader, 1 should not know // of custom classes val rootloader = { // recursive method find loader without parent def parent(loader:classloader):classloader = { val p = loader.getparent if (p == null) loader else parent(p) } parent(getclass.getclassloader) } // check if custom classfile available rootloader val classname = classof[my.custom.servlet.classfile].getname val classavailable = seek { rootloader.loadclass(classname) true } grab { case e:classnotfoundexception => false } // if i'm not insane no error thrown if (classavailable) sys.error("class should not available") // create webappcontext using empty webappclassloader // based on rootloader val context = new webappcontext() context.setparentloaderpriority(false) //context.setclassloader(new webappclassloader(rootloader, context)) context.setclassloader(rootloader) context.setcontextpath("/") context.setdescriptor(webxmlfile) context.setresourcebase(resourcebase) // create start server context val server = new server(port) server.sethandler(context) server.start()
i expected context not find class in question.
ok eecolor, i've had dig around in code , think have 2 issues i've opened these bugs:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=447462 https://bugs.eclipse.org/bugs/show_bug.cgi?id=447461now, bug #1 reason why if set isolated classloader webapp magically able still load class. bug #2 shouldn't impact you, unless start play around joakim's suggestion of setting scheme , server classes, , you're ok, because class exists in both container classloader parent hierarchy , webapp classloader , bug occurs when scheme class missing container classloader nowadays in webapp classloader.
so, can seek using joakim's suggestion of adding class scheme class , should work. alternatively, should able set webappcontext.setparentloaderpriority(true) , seek container classloader hierarchy first. although aware setparentpriority(true) apply classloading webapp, whilst joakim's suggestion limits different loading behaviour class in question.
jan
java scala jetty embedded-jetty
Comments
Post a Comment