On 10/10/2011 18:51, Peter Lavin wrote: > Hi Filippo, tks for your reply. > > I'm not actually specifying any ClassLoader, perhaps I should? How > should I specify a ClassLoader to use when dynamically loading a class?
You can pass one into the Constructor of your own classloader: public CustomClassloader(ClassLoader parent) { super(parent); } p > Filippo Machi wrote: >> Ciao Piter, >> usually class loaders are arranged unto a hierarchy, who's the parente >> classloader of the one you're using to define the class fronte the byte >> array? It should've be the classloader whose scope us your webapp.. >> Hth >> Fil >> Il giorno 10/ott/2011 19.27, "Peter Lavin" <lav...@cs.tcd.ie> ha scritto: >> >>> Dear Users, >>> I am running web-services (developed in CXF) in a Tomcat 7.0.14 server, >>> Java version "1.6.0_17", OS, Linux <hostname> 2.6.18-238.9.1.el5 #1 >>> SMP Tue >>> Apr 12 18:10:13 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux >>> >>> >>> Part of my service code takes a byte array and defines a class using its >>> contents which was not previously loaded in the JVM, code snippet as >>> follows... >>> >>> Class<?> c = defineClass(name, byArray, 0, byArray.length); >>> >>> This code is in a class which extends java.lang.ClassLoader. >>> >>> The class represented by the byte array btArray is a class which >>> extends a >>> super class. >>> >>> Background... >>> * Dynamic loading of a class this way works in the IDE (Eclipse) >>> when not >>> running in a Tomcat server. >>> * The super class from which the loaded class extends is included in >>> the >>> war file, the files are present on the tomcat server. >>> * When loading a class which does not extend a super class (no >>> inheritance), the above code works fine within the service in Tomcat. >>> * When using a class which implements an interface an interface but no >>> inheritance, it also fails (with the following exception). >>> * When using a class which implements an interface which is in >>> java.io.*, >>> e.g. Serializable, the class loads ok within the Tomcat server. >>> >>> I have tried to use WebappClassloader, but cannot get the service to >>> deploy >>> when this class is imported from catalina.jar. >>> >>> Relevant parts of the error output is pasted here... >>> >>> WARNING: Application {http://peteragent.sga.org/}** >>> AgentServiceImplService#{http:**//peteragent.sga.org/}process<http://peteragent.sga.org/%7DAgentServiceImplService#%7Bhttp://peteragent.sga.org/%7Dprocess>has >>> thrown exception, unwinding now >>> org.apache.cxf.interceptor.**Fault: >>> common/core/**AbstractServiceProvider >>> at org.apache.cxf.service.**invoker.AbstractInvoker.** >>> createFault(AbstractInvoker.**java:155) >>> [...abridgment...] >>> Caused by: java.lang.**NoClassDefFoundError: common/core/** >>> AbstractServiceProvider >>> at java.lang.ClassLoader.**defineClass1(Native Method) >>> at java.lang.ClassLoader.**defineClass(ClassLoader.java:**632) >>> at java.lang.ClassLoader.**defineClass(ClassLoader.java:**478) >>> at common.utilities.ClassLoading.**FileClassLoader.loadClass(** >>> FileClassLoader.java:24) >>> [end] >>> >>> >>> My questions, has anyone also had this problem? >>> Is WebappClassLoader designed to overcome this problem? >>> Does anyone know why the class loads, but the JVM/ClassLoader is >>> unable to >>> find the super classes (although they are present). I'm aware that >>> Tomcat >>> uses a different ClassLoader for each webapp, but the required classes >>> should be present in the ClassLoader of the webapp in question as >>> they are >>> in the war, and are in the file >>> .../webapps/serviceName/WEB-**INF/classes/ >>> directory. >>> >>> >>> with thanks, >>> Peter >>> >>> >>> -- >>> with best regards, >>> Peter Lavin, >>> PhD Candidate, >>> Computer Architecture & Grid Research Group, >>> Lloyd Institute, 005, >>> Trinity College Dublin, Ireland. >>> +353 1 8961536 >>> >>> ------------------------------**------------------------------**--------- >>> >>> To unsubscribe, e-mail: >>> users-unsubscribe@tomcat.**apache.org<users-unsubscr...@tomcat.apache.org> >>> >>> For additional commands, e-mail: users-h...@tomcat.apache.org >>> >>> >> >
signature.asc
Description: OpenPGP digital signature