Class Loading on specific diretory

I am writing a plugin based engine and I want to load up my classes(plugins) from a specific directory besides "classes/com/bla/bla/bla"
So, I am using this code:
URL[] url = new URL[1];
try {
url[0] = new URL("file:think/");
catch (MalformedURLException ex) {
URLClassLoader ucl = new URLClassLoader(url);
try {
Class cl = ucl.loadClass(pluginsPackage + "." + "Updater");
System.out.println(cl);
catch (ClassNotFoundException ex1) {
ex1.printStackTrace();
Actually, if I try something like this:
new File("think").list()
will return all my .class files located under that directory.
Another doubt. when I call URLClassLoader.loadClass(string) I must pass the whole class name like "bla.blabla.blabla.myclass" or just "myclass"
Class cl = ucl.loadClass("org.com.info.net.thing.Updater")
(By the way, this ucl.loadClass is giving me the ClassNotFoundException!)
OR
Class cl = ucl.loadClass("Updater")
(By the way, this ucl.loadClass is giving me the NoClassDefFoundError!)
What Am I doing wrong ?
If anybody had an idea, please contact me at msn([email protected]) or reply this topic. thank you!

Actually, if I try something like this:
new File("think").list()
will return all my .class files located under that
directory.
Is there a question here?No! Thats a statement!
I am telling that under my current directory, there is a another one, filled with .class files containing classes implementing some base Interface. That interface will be used to instantiate the object.
Right ?
Apparently you don't have the class you specified in the right place.Well.. Here is the thing...
Even if I set the url using something like this:
url[0] = new File("think").toURL();(You know. this File objet is ok.)
and then:
URLClassLoader ucl = new URLClassLoader(url);
Class cl = ucl.loadClass(pluginsPackage + "." + "Updater");(pluginsPackage + "." + "Updater" = "bla.bla.bla.bla.Updater" )
(just like you guys told me to do. Fully qualified class name)
And then:
java.lang.ClassNotFoundException: br.com.rsl.agent.plugins.think.Updater
     at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
     at java.security.AccessController.doPrivileged(Native Method)
     at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
where is the failure ?
:(

Similar Messages

  • How to load a class dynamically in the current/system class loader

    I need to dynamically load a new jdbc driver jar to the current/system class loader... Please note that creating a new classloader will not help since the DriverManager refers to the systemclassloader itself.
    Restarting the application by appending the jar to its classpath will solve the problem but I want to avoid doing this.

    Did you then create a ClassLoader to load the JDBC
    driver and then install it into the system as
    directed by the JDBC specification (ie
    Class.forName(someClassName))?
    And then try to use it from a class loaded fromsome
    other ClassLoader (i.e. the system class loader)?
    If you did not try this please explain why not.O.K. I just looked at the source to
    java.sql.DriverManager. I did not know what I was
    talking about, as what I suggested above will not
    work.
    This is my new Idea:
    Create a URLClassLoader to load the JDBC driver also
    in this ClassLoader you need to place a helper class
    that does the following:
    public class Helper {
    public Driver getJDBCDriver(String driverClassName,
    String url) {
    try {
    Class.forName(driverClassName);
    Driver d = DriverManager.getDriver(url);
    return d;
    catch(Exception ex) {
    ex.printStackTrace();
    return null;
    }Now create an instance of the Helper class in the new
    ClassLoader, and call its getJDBCDriver method to get
    an instance of the driver (you will probably have to
    create an interface in the root class loader that the
    Helper implements so that you can easily call it).
    Now from the root classloader you can make calls
    directly to the returned Driver and bypass the
    DriverManager and its restrictions on cross
    ClassLoader access.
    The only catch here is that you would have to call to
    the returned Driver directly and not use the Driver
    Manager.This sounds like will work but I did not want to load DriverManager in a new classloader.. I did a hack
    I unzip the jar dynamically in a previously known location (which I included in my classpath when launching the app). The classLoader finds the class now though it did not exist when the app was launched !
    A hack of-course but works eh ..

  • Problem in Class Loading

    I am using Sun implementation of JAXB(jaxb-api.jar) for java-to-xml binding in my web application deployed in the latest version of oracle app server(10g release 3). The web server is loading Oracle implementation of JAXB from the shared archive xml.jar. To direct the web server to load application specific JAXB classes, I have used the property(<web-app-class-loader search-local-classes-first="true" include-war-manifest-class-path="false" />) in the deployment description - orion.xml file. But it does not solve the problem!
    Thanks & regards

    Hi,
    Refer to this link on OC4J's Classloading Framework... http://download-east.oracle.com/docs/cd/B25221_04/web.1013/b14433/classload.htm#sthref58 there are a couple of options you may be able to employ, including overriding the shared library - there is an example of doing this with the Oracle XML parser and Xerces.
    I'm guessing you're on the right track, but you may want to try include-war-manifest-class-path="true". Also, are you sure that you've got your deployment descriptor file defined correctly? Its normally called orion-application.xml, and that particular element isn't defined in the documentation (http://download-east.oracle.com/docs/cd/B25221_04/web.1013/b14433/descriptors.htm#sthref337). You could always try configuring it through the administration console.

  • Dynamic Class Loading in an EJB Container

    Hello,
    We have a need to load classes from a nonstandard place with in an ejb container, ie a database or secure store. In order to do so we have created a custom class loader. Two issues have come up we have not been able to solve, and perhaps some one knows the answer to.
    Issue 1.
    Given the following code:
    public static void main(String args[])
    MyClassLoader loader = new MyClassLoader("lic.dat");
    System.out.println("Loading class ..." + "TestObject");
    Object o = Class.forName("TestObject",true,loader).newInstance();
    System.out.println("Object:" + o.toString());
    TestObject tstObj = (TestObject) o;
    tstObj.doIt();
    What happens when executed is as follows. Class.forName calls our loader and does load the class as we hoped, it returns it as well, and the o.toString() properly executes just fine. The cast of the object to the actual TestObject fails with a class not found exception. We know why this happens but don't know what to do about it. It happens because the class that contains main was loaded by the system class loader (the primordial class loader as its sometimes called), That class loader does not know about TestObject, so when we cast even though the class is "loaded" in memory the class we are in has no knowledge of it, and uses its class loader to attempt to find it, which fails.
    > So the question is how do you let the main class know to use our class loader instead of
    the system class loader dispite the fact is was loaded by the system class loader.
    Issue 2:
    To make matters worse we want to do this with in an EJB container. So it now begs the question how do you inform an EJB container to use a specific class loader for some classes?
    Mike...

    Holy crap! We are in a similar situation. In creating a plugin engine that dynamically loads classes we use a new class loader for each plugin. The purpose is so that we can easily unload and/or reload a class at runtime. This is a feature supposedly done by J2EE app servers for hot-deploy.
    So our plugins are packaged as JAR files. If you put any class in the CLASSPATH, the JVM class loader (or the class loader of the class that is loading the plugin(s)), will load the class. The JavaDoc API states that the parent classloader is first used to see if it can find the class. Even if you create a new URLClassLoader with NULL for parent, it will always use the JVM class loader as its parent. So, ideally, in our couse, plugins will be at web sites, network drives, or outside of the classpath of the application and JVM.
    This feature has two benefits. First, at runtime, new updates of plugins can be loaded without having to restart the app. We are even handling versions and dependencies. Second, during development, especially of large apps that have a long startup time, being able to reload only one plugin as opposed to the annoying startup time of Java apps is great! Speeds up development greatly.
    So, our problem sounds just like yours. Apparently, the Client, which creates an instance of the plugin engine, tries to access a plugin (after the engine loades it via a new classloader instance for each plugin). Apparently, it says NoDefClassFound, because as you say, the client classloader has no idea about the plugin class loaded by another classloader.
    My co-developer came up with one solution, which I really dont like, but seems to be the only way. The client MUST have the class (java .class file) in its classpath in order to work with the class loaded by another class loader. Much like how in an EJB container, the web server calling to EJB MUST contain the Home and Remote interface .class files in its classpath, the same thing needs to be done here. For us, this means if a plugin depends on 5 others, it must contain ALL of the .class files of those plugins it depends on, so that the classloader instance that loads the plugin, can also see those classes and work with them.
    Have you got any other ideas? I really dislike that this has to be done in this manner. It seems to me that the JVM should be able to allow various class loaders to work with one another in such a way that if a client loaded by one classloader has an import statement in it to use a class, the JVM should be able to fetch the .class out of the other classloader and share it, or something!
    This seems to me that there really is no way to actually properly unload and then reload a class so that the JVM will discard and free up the previous class completely, while using the new class.
    I would be interested in discussing this topic further. Maybe some others will join in and help out on this topic. I am surprised there isn't a top-level forum topic about things like class loaders, JVM, etc. I wish there was a way to add one!

  • Dynamic class loading in J2ME

    Hi all,
    Couple of questions. Is dynamic class loading using classloaders supported in any, if not all versions of J2ME? I guess I should ask first, what exactly does J2ME cover? I see KVM, but do watches and PDA's, set top boxes, refrigerators and so forth all run the same J2ME JVM? Or are their "less feature full" versions? I was hoping the J2ME spec would be the "lowest common denominator" to program for, but I thought I read somewhere that small devices like watches may even have a "smaller" J2ME JVM or something, less capable. So can I write code for J2ME and it will run on all small devices like cell phones, pda's, and so forth? Or is there another J2ME version, perhaps small than J2ME.
    So, from what I have found so far, it appears dynamic class loading is done at startup from a DB (of sorts) as opposed to being able to dynamically find/load classes. If this is so, is there any way to support downloading and reloading new classes like you can with J2SE, such as the hot-swap feature of web servers? Does Class.forName() at least work in that you can "replace" a class with a new version, even if it is not able to have a separate classloader instance? My guess is that J2ME supports only a single classloader space, but I thought I read somewhere that Class.forName() is available. J2ME API shows it I believe, but I could be wrong.
    Any help on this topic would be appreciated.
    Thanks.

    Dynamic class loading is not available in most (if not all) J2ME profiles and configurations. Class.forName() is available (at least in the MID profile), but not to be used for dynamic class loading. It can be used when using device-specific APIs where you can try to load a class containing device specific methods (for example a class that works only on certain Nokia phones, and has methods playSound() and vibrate(), which are not available in MIDP), and if you catch a ClassNotFound exception you can load a class that doesn't use the device specific APIs and contains stubs of the methods, or you can disable certain features in you application that need those features. For an example implementation you can have a look at Nokia's Block Game example (available from their developer site - http://www.forum.nokia.com/main.html).
    As for your other more general questions about different JVM's and such, you should read all about the different configurations and profiles available in J2ME (plenty of information using in the J2ME link on this site).

  • Dynamic Class Loading with interface

    Hello
    I would appreciate any help on the following problem.
    I need to load all classes in a particular directory and its subdirectories (top directory is known but not in the classpath) which implement a predefined interface. At the moment I am using a lot of reflection to accomplish this and believe it can be avoided somehow using the fact that I know these classes have to implement a predefined interface.
    At the moment, I am searching through the directory and subdirectory, loading all names of classes into a vector using a custom URLClassloader, and then load all classes in the vector into modulecontainers to populate a defaultmutabletree which is displayed on the gui.
    I'm sure that knowing the interface means there's a more straightforward way.
    Thanks in advance.

    Finally i've found out myself, i've read some postings in this forum and put them all together, so that my webstart-application finally works the way i want...
    That was the topic:
    Downloading a jar-file and starting a class from this jar-file within a webstart application (dynamic class loading).
    I'll post my final solution for this problem, may be it would be useful in future for anyone else.
    //grant all permissions on the clientside
    Policy.setPolicy( new Policy() {
    public PermissionCollection getPermissions(CodeSource codesource) {
    Permissions perms = new Permissions();
    perms.add(new AllPermission());
    return(perms);
    public void refresh(){
    //get the current classloader
    ClassLoader cl = MyLoadedClass.class.getClassLoader();
    //create a new url-classloader while using the current classloader
    URL[] urls = new URL[1];
    File f = new File(new String(jarName));
    urls[0] = f.toURL();
    URLClassLoader ul = new URLClassLoader(urls, cl);
    //load a class from jarfile
    Class c = ul.loadClass(new String(className));
    //get an object from loaded class
    Object o = c.newInstance();
    /* Are we using a class we specifically know about? */
    if (o instanceof KnownInterface){
    // Yep, lets call a method we know about. */
    KnownInterface client = (KnownInterface) o;
    client.doAnything();

  • Dynamic class loading with Webstart

    Hello !
    //within the jar-file at the webstart-directory
    public interface MyFrame{
    public void createFrame();
    //within the jar-file dynamically downloaded
    public class MyExtFrame extends JFrame implements MyFrame{
    String className = "MyExtFrame";
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    JarClassLoader jarLoader = new JarClassLoader (cl, jarFile));
    /* Load the class from the jar file and resolve it. */
    Class c = jarLoader.loadClass (className, true);
    /* Create an instance of the class.
    Object o = c.newInstance();
    /* Are we using a class we specifically know about? */
    if (o instanceof MyFrame){
    // Yep, lets call a method we know about. */
    MyFrame client=(MyFrame) o;
    //call a class-method (here creates the whole gui-object at once)
    client.createFrame();
    This is the code i'm using and i've encountered following problem, if i put this code into an application without webstart, anything works fine, but with webstart i'll get a: java.lang.NoClassDefFoundError
    Then i've put the MyFrame-classes into the downloaded jar-file, but this won't work either, i'll get a ClassCastException.
    What do i have to do, to become it working ?
    Thanks for any conclusions and help.
    Michael

    Finally i've found out myself, i've read some postings in this forum and put them all together, so that my webstart-application finally works the way i want...
    That was the topic:
    Downloading a jar-file and starting a class from this jar-file within a webstart application (dynamic class loading).
    I'll post my final solution for this problem, may be it would be useful in future for anyone else.
    //grant all permissions on the clientside
    Policy.setPolicy( new Policy() {
    public PermissionCollection getPermissions(CodeSource codesource) {
    Permissions perms = new Permissions();
    perms.add(new AllPermission());
    return(perms);
    public void refresh(){
    //get the current classloader
    ClassLoader cl = MyLoadedClass.class.getClassLoader();
    //create a new url-classloader while using the current classloader
    URL[] urls = new URL[1];
    File f = new File(new String(jarName));
    urls[0] = f.toURL();
    URLClassLoader ul = new URLClassLoader(urls, cl);
    //load a class from jarfile
    Class c = ul.loadClass(new String(className));
    //get an object from loaded class
    Object o = c.newInstance();
    /* Are we using a class we specifically know about? */
    if (o instanceof KnownInterface){
    // Yep, lets call a method we know about. */
    KnownInterface client = (KnownInterface) o;
    client.doAnything();

  • InitialContext Class Loader

    Hi all,
    We are experiencing a strange behaviour of the Application Class Loader. Our main issue is that if we deploy 2 applications using our code, the first application is okay, and the second application fails its loading. During the loading, we instantiate a customized InitialContextFactory (two times at all: one time per application). As a result, we have a ClassCastException in our customized InitialContext. Above a more detailed explanation of what happen. To sum up, we think that our InitialContextFactory is loaded by a master class loader, only one time for the 2 applications, and that the second application reaches the customized InitialContextFactory instantiated for the first application, so the classes loaded for the second application are not compatible.
    Details:
    - Each Application create a new InitialContext with the parameter "java.naming.factory.initial" equals to "com.test.CustomInitialContextFactory".
    - In the class com.test.CustomInitialContextFactory we access to other code from our application, which are passed to the context factory by the environment hashtable. In the method public javax.naming.Context getInitialContext(java.util.Hashtable env), we get some parameters from the env parameter like that: CustomObject o = (CustomObject)env.get("com.test.customObject");
    When the first application launches, it works very well.
    When the second application launches, it fails with a ClassCastException on the class com.test.CustomObject. We think that the class com.test.CustomObject is not loaded by the good class loader so it throws a ClassCastException.
    Thank you for your help

    We have found how the JNDI layer builds the specified context factory:
              ClassLoader cl = (ClassLoader) AccessController.doPrivileged(
                   new PrivilegedAction() {
                   public Object run() {
                        return Thread.currentThread().getContextClassLoader();
    But OC4J has specific Thread ClassLoader: this is the cause of all our problem. So there is a solution: create a specific context factory which calls the good class loader to load the context factory.
    Bye

  • Order of class loading in a Web Application

    Hi,
    I have been trying to find out if there is a defined order in which classes contained in WEB-INF/classes
    and/or WEB-INF/lib should be loaded.
    There doesn't appear to be any mention of class loading order in either the J2EE 1.3 or J2EE 1.4
    specifications. That does not mean that there isn't a defined class load order, it just means I haven't found one.
    Typical behaviour from servers such as Tomcat (reference implementation of the Servlet Engine) show
    that classes in WEB-INF/classes are loaded before classes contained in jars under WEB-INF/lib.
    Because there doesn't appear to be a mandated class load order I cannot assume that the same
    behaviour holds for all servers, unless someone here knows better of course.
    The reason for the question is that relying on the exhibited class load order means we can patch web applications by simply putting the patch under the WEB-INF/classes directory.
    If this should not be relied upon then patches will have to be applied directly to the affected jar files,
    this is not a problem in itself however it is nice to be able to keep the patches out of the jars for
    ease of rolling back patches without having to copy jar files all over the place.
    Any insights would be welcome.
    Thanks

    If you say that it is server specific i don't find
    that to be the correct answer b'cozI didn't give an answer, I am looking for one. I gave an example of the behaviour that Tomcat 4.1.x
    exhibits, one that we currently make use of for patching web applications. My question was about
    whether or not this behaviour can be relied upon.
    the class files are depended on the jar files which
    need to checked in first before getting loaded b'coz
    it should check for dependent files before only while
    getting deployed.This is why the class load order is important.
    Is the Web Application Classloader going to look in WEB-INF/classes first every time followed
    by WEB-INF/lib everytime, is the order undefined, or is it reversed?
    More over if you just think of class loading mechanism
    of classes folder only then it is loaded in the order
    specified in the web.xml file.
    in this we specify the order of loading.As far as I know web.xml does not allow you to specify where classes should be loaded from and in
    which classpath order, you define which classes should be used for application components.
    The only load order you can specify is the load order of servlets on startup.
    If you know different I would love to know how you would configure web.xml to specify the classpath order
    in which classes are loaded.

  • Can class loading be affected by concurrency ?

    I remember having read that class loading is guaranteed to happen on a single thread, ie. that static initializer blocks do not need to worry about being invoked concurrently.
    I can't find any longer the source that stated that; so is anyone able to tell me if that's true (and point me to a resource about that) ?
    I could find that java.lang.ClassLoader
    defines a :
    protected synchronized Class loadClass(String name, boolean resolve)
    but I imagine a case where a classloader overrides that method without keeping the synchronization AND a class to be loaded is referenced from many parts of a multithreaded system, so it may happen that multiple thread attempt to load it.
    is this a real scenario ?
    TIA,
    Edo

    Hello,
    Based on the JVM specifications, when a class or interface is initialized (execution of the static initializers) the "Java Virtual Machine is responsible for taking care of synchronization". The very first step of the procedure for initializing a class or interface is to "synchronize on the Class object that represents the class or interface to be initialized".
    Now, the questions are:
    How to interpret the specifications? Are the JVM implementations compliant?
    Personally, when I write some static initializer blocks, I do NOT worry about multi-threading issues. But I may be wrong.
    For instance, I write:
    class Singleton {
      private static Singleton SINGLETON = new Singleton();
      public Singleton getInstance() { return SINGLETON };
    }and not:
    class Singleton {
      private static Singleton SINGLETON;
      static {
        synchronized(Singleton.class) {
          SINGLETON = new Singleton();
      public Singleton getInstance() { return SINGLETON };
    }I hope it helps.

  • Custom class loader and local class accessing local variable

    I have written my own class loader to solve a specific problem. It
    seemed to work very well, but then I started noticing strange errors in
    the log output. Here is an example. Some of the names are in Norwegian,
    but they are not important to this discussion. JavaNotis.Oppstart is the
    name of my class loader class.
    java.lang.ClassFormatError: JavaNotis/SendMeldingDialog$1 (Illegal
    variable name " val$indeks")
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:431)
    at JavaNotis.Oppstart.findClass(Oppstart.java:193)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at JavaNotis.SendMeldingDialog.init(SendMeldingDialog.java:78)
    at JavaNotis.SendMeldingDialog.<init>(SendMeldingDialog.java:54)
    at JavaNotis.Notistavle.sendMelding(Notistavle.java:542)
    at JavaNotis.Notistavle.access$900(Notistavle.java:59)
    at JavaNotis.Notistavle$27.actionPerformed(Notistavle.java:427)
    JavaNotis/SendMeldingDialog$1 is a local class in the method
    JavaNotis.SendMeldingDialog.init, and it's accessing a final local
    variable named indeks. The compiler automatically turns this into a
    variable in the inner class called val$indeks. But look at the error
    message, there is an extra space in front of the variable name.
    This error doesn't occur when I don't use my custom class loader and
    instead load the classes through the default class loader in the JVM.
    Here is my class loading code. Is there something wrong with it?
    Again some Norwegian words, but it should still be understandable I hope.
         protected Class findClass(String name) throws ClassNotFoundException
             byte[] b = loadClassData(name);
             return defineClass(name, b, 0, b.length);
         private byte[] loadClassData(String name) throws ClassNotFoundException
             ByteArrayOutputStream ut = null;
             InputStream inn = null;
             try
                 JarEntry klasse = arkiv.getJarEntry(name.replace('.', '/')
    + ".class");
                 if (klasse == null)
                    throw new ClassNotFoundException("Finner ikke klassen "
    + NOTISKLASSE);
                 inn = arkiv.getInputStream(klasse);
                 ut = new ByteArrayOutputStream(inn.available());
                 byte[] kode = new byte[4096];
                 int antall = inn.read(kode);
                 while (antall > 0)
                     ut.write(kode, 0, antall);
                     antall = inn.read(kode);
                 return ut.toByteArray();
             catch (IOException ioe)
                 throw new RuntimeException(ioe.getMessage());
             finally
                 try
                    if (inn != null)
                       inn.close();
                    if (ut != null)
                       ut.close();
                 catch (IOException ioe)
         }I hope somebody can help. :-)
    Regards,
    Knut St�re

    I'm not quite sure how Java handles local classes defined within a method, but from this example it seems as if the local class isn't loaded until it is actually needed, that is when the method is called, which seems like a good thing to me.
    The parent class is already loaded as you can see. It is the loading of the inner class that fails.
    But maybe there is something I've forgotten in my loading code? I know in the "early days" you had to do a lot more to load a class, but I think all that is taken care of by the superclass of my classloader now. All I have to do is provide the raw data of the class. Isn't it so?

  • Why do we use only dynamic class loading for JDBC drivers

    Hi,
    My JDBC experience is that we always use dynamic class loader for drivers.
    If we have a well defined package from a vendor, why do we use this dynamic class loading feature for drivers??

    chandunitw wrote:
    Hi,
    My JDBC experience is that we always use dynamic class loader for drivers.
    If we have a well defined package from a vendor, why do we use this dynamic class loading feature for drivers??Oftentimes, the driver class name is set in a configuration file, not in code. So the thing which processes the configuration file has no idea ahead of time which driver or drivers it will support, so it is not coded specifically for any. So it loads the driver by reflection, since it is given the class name as a string it can use with the reflection API.

  • Increasing number of class loaded. Class leak?

    Hi there,
    I am concern about the high number of classes loaded by one application. Using JConsole I see linear time raising in the number of classes loaded, after monitoring that for about 24 hours the number of loaded classes continues increasing (more than 100.000), while the number of unloaded classes is less than 0.5%. So far no memory leak was observed after 24 hours.
    I guess there is a logical leak in the application but I don't understand why this has no effect on the memory usage.
    - Do you know about the possible reasons / side effects of this ugly class leak behavior?
    - I've tried to find out more info about the class loading, but it seems to be a kind of tricky to self manage the loading/unloading process.
    I'd really appreciate any information/documentation/experiences.
    Thanks in advance.

    What makes you think there is a 'logical leak'? I'm not sure about it, but I guess something is not working fine, as the classes remain loaded and they are not unloaded. So, a logical leak preventing the classes to be unloaded is not hard to believe. Maybe (and hopefully) I am wrong
    The number of loaded classes? How many classes do you expect to be loaded vs the number of those that are actually loaded? I don't expect any specific number, what I expect is that the number of loaded classes does not increase linearly with the time. I mean, I expect a similar graph as the memory usage :)
    Probably I am wrong but for me it does not seem normal that the classes are never unloaded ???

  • Weblogic Class Loading issue

    Note: I am not sure what is the best suitable subject for this issue.
    Stack Trace:
    Error 1)
    &lt;Dec 30, 2011 11:02:51 AM GMT+05:30&gt; &lt;Error&gt; &lt;HTTP&gt; &lt;BEA-101017&gt; &lt;[ServletContext@29472630[app:EM11X module:Web path:/Web spec-version:2.5], request: weblogic.servlet.internal.ServletRequestImpl@14d05d1[
    POST /Web/GenerateMealPlanAction.do HTTP/1.1
    Via: 1.1 INDCHN-MGMT01
    Cookie: org.ditchnet.jsp.tabs:CommercialFormulaTabs=; org.ditchnet.jsp.tabs:KitchenTabs=; JSESSIONID=sZQFT9MJQc6vS6MCSXtdjWwSTLCcG6nqL12Fdyj1NFHcp4WnpkCB!1348500068
    Referer: http://130.78.88.83:7001/Web/GenerateMealPlanAction.do?vo.viewCode=generateMealPlanFrame&method=1&&menu_id=DS_DFLT&module_id=DS&function_id=DS_GEN_MEAL_PLAN&function_name=Generate%20Meal%20Plan&function_type=R&access=YYYYN&desktopFlag=N&vo.functionId=DS_GEN_MEAL_PLAN
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; InfoPath.1)
    Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
    Accept-Language: en-us
    Pragma: no-cache
    Connection: Keep-Alive
    Content-Length: 488
    ]] Root cause of ServletException.
    java.lang.IllegalArgumentException: Cannot invoke com.vo.GenerateMealPlanVO.setServingDate on bean class 'class com.vo.GenerateMealPlanVO' - argument type mismatch - had objects of type &quot;java.lang.String&quot; but expected signature &quot;com.core.util.Date&quot;
         at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2181)
         at org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(PropertyUtilsBean.java:2141)
         at org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(PropertyUtilsBean.java:1948)
         at org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtilsBean.java:2054)
         at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:1015)
         Truncated. see log file for complete stacktrace
    Caused By: java.lang.IllegalArgumentException: argument type mismatch
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2155)
         Truncated. see log file for complete stacktrace
    &gt;
    Error 2)
    &lt;Dec 30, 2011 11:11:19 AM GMT+05:30&gt; &lt;Error&gt; &lt;HTTP&gt; &lt;INDCHN-EPORT01&gt; &lt;AdminServer&gt; &lt;[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'&gt; &lt;&lt;WLS Kernel&gt;&gt; &lt;&gt; &lt;&gt; &lt;1325223679258&gt; &lt;BEA-101017&gt; &lt;[ServletContext@29472630[app:EM11X module:Web path:/Web spec-version:2.5], request: weblogic.servlet.internal.ServletRequestImpl@1da8bfe[
    POST /Web/LookupAction.do HTTP/1.1
    Via: 1.1 INDCHN-MGMT01
    Cookie: org.ditchnet.jsp.tabs:CommercialFormulaTabs=; org.ditchnet.jsp.tabs:KitchenTabs=; JSESSIONID=GhG4T9TJ0ytD8dhRSGBFv2c3v1hNLftTTCJQHp6Qn9C5SnMGTVYF!1348500068
    Referer: http://130.78.88.83:7001/Web/core/lookup/jsp/LookupCriteria.jsp?undefined
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; InfoPath.1)
    Accept: */*
    Accept-Language: en-us
    Pragma: no-cache
    Connection: Keep-Alive
    Content-Length: 304
    ]] Root cause of ServletException.
    java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
         at com.lookup.pojo.web.LookupAction.doActionQuery(LookupAction.java:107)
         at com.core.pojo.web.BaseAction.execute(BaseAction.java:97)
         at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)
         at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
         at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3717)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
    &gt;
    [b]Analysis:
    Migrating J2EE Application from Oracle 10g Application Server to Oracle 11g Weblogic Server. I am stuck with above two issues. This issue not present while running in Oracle 10g Application Server
    1) I was thinking it is something to do with JSTL versions and the below command is executed to make the JSTL version to jstl 1.1.2
    java weblogic.Deployer -adminurl t3://localhost:7001 -user weblogic -password weblogic -deploy -library D:/Oracle/Middleware/wlserver_10.3/common/deployable-libraries/jstl-1.1.2.war
    The problem remains same.
    2) Now &lt;wls:prefer-web-inf-classes&gt;true&lt;/wls:prefer-web-inf-classes&gt; is added to weblogic.xml to make the Web application to load application specific libraries from WEB-INF/lib directory.
    The problem remains same.
    3) I checked Class Loader Analysis Tool and found conflicting classes and based on CAT recommendation the below list is added to weblogic.xml and &lt;wls:prefer-web-inf-classes&gt;true&lt;/wls:prefer-web-inf-classes&gt; is removed since both cannot co-exist.
         &lt;wls:prefer-application-packages&gt;
                   &lt;wls:package-name&gt;antlr.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;antlr.collections.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;antlr.collections.impl.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;antlr.debug.misc.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;com.mysql.jdbc.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.ejb.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.ejb.spi.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.enterprise.deploy.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.jms.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.management.j2ee.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.resource.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.resource.cci.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.resource.spi.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.security.jacc.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.servlet.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.servlet.http.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.servlet.jsp.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.transaction.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.transaction.xa.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.datatype.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.namespace.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.parsers.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.registry.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.transform.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.validation.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;javax.xml.xpath.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.core.lmx.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.core.lvf.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.aq.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.connector.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.dcn.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.diagnostics.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.driver.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.internal.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.oci.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.oracore.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.pool.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.rowset.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.util.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jdbc.xa.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jpub.runtime.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.jsp.provider.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.ano.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.aso.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.jdbc.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.jndi.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.ns.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.nt.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.net.resolver.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.security.o3logon.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.security.o5logon.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.sql.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;oracle.sql.converter.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.apache.commons.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.apache.derby.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.apache.oro.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.apache.xerces.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.apache.xmlcommons.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.gjt.mm.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.joda.time.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.w3c.dom.*&lt;/wls:package-name&gt;
                   &lt;wls:package-name&gt;org.xml.sax.*&lt;/wls:package-name&gt;
              &lt;/wls:prefer-application-packages&gt;
    The problem remains same.
    Your help is greatly appreciated as I am stuck with this issue.

    No I cannot ignore this error while deplyment. I'm not able to deploy the war.
    More ovet this needs to be working as during startup, the servlet loads some xml files and convert into tables for the kiosk in the airport to be working.
    Edited by: [email protected] on Mar 27, 2009 12:24 PM

  • Cusotm Class Loader

    I'm trying to use a custom class loader to load specific classes (not handle everything). So in those particular situations I call my custom class loader's loadClass method which will first check for a .class file in a specific directory and use that, otherwise it will get from classpath.
    While testing, it worked perfectly fine. If I didn't put a class file in the directory it used the one from classpath, but as soon as I put the class in the directory then that class would override whatever was in my classpath- perfect.
    However, when I deployed this to WebLogic, the system broke. It seems to load the class fine but during class definition it can not find the other objects I reference within the class, so I get NoClassDefFoundError errors.
    Here's what the code looks like:
        public synchronized Class loadClass(String className, boolean resolveIt, String filePath)
             throws ClassNotFoundException {
            Class result;
            byte  classData[];
            /* Check our local cache of classes */
            result = (Class)classes.get(className);
            if (result != null) {
                return result;
            /* Try to load it from our repository */
            classData = getClassFromFile(className, filePath);
            if (classData != null) {   
                //System.out.println(" found in file");
                /* Define it (parse the class file) */
                result = defineClass(classData, 0, classData.length);
                if (result == null) {
                    throw new ClassFormatError();
                if (resolveIt) {
                    resolveClass(result);
                classes.put(className, result);
                return result;               
            /* Try the classpath */
            return Class.forName(className);
        }any idea what's up?

    I think the "linkage" to types(classes, interfaces) referenced by a class are resolved at the resolveClass method, not the defineClass method. Are you sure that's the method throwing the exception?
    anyway, what I meant is that when a class loaded by your classloader is resolved(linked to all refernced types), the referenced types are searched by your classloader, so you have to ensure it delegates to the appropriate class loader.
    lets say your WebLogic server configuration consists of an EJB/dependency classloader, and a descendent WAR classloader.
    If for example, your classloader is located in a dependency jar, hence loaded by the EJB/dependency classloader, any classes loaded by it that refer to types in the WAR will fail, because they will never get to the WAR classloader.
    I think you should simply create your classloader with a specified parent instead of relying on the classloader that loaded it as a parent.
    Better yet -> I know there are configurations that can be done on some servers(I don't have expirience with WebLogic, but I know it can be done with WebSphere) to configure the behavior you are looking for.
    for example, setting delegation mode to "parent last" on a WAR classloader if you want all classes in WEB-INF/lib to have "priority" over classes on server classpath.
    If this is possible in your case I'm sure it's better than messing around with implementing a custom classloader...

Maybe you are looking for