Class Loader confusion

I am trying to use java.net.URLClassLoader to load classes dynamically from jar files. The strange thing is, I can only get this to work successfully with one particular Jar file. With any other Jar file I have tried, I get a java.lang.NoClassDefFoundError. I'm trying to figure out what is different about this particular jar file.
The first thing I should point out is that when I create the URLClassLoader, I can successfully load the appropriate classes using loadClass(). So I am not mistyping the filename of the Jar or anything like that.
It's only when I try to create an instance of a class that is not in the Jar but uses a class in the Jar file, that I get the NoClassDefFoundError.
The second thing I have noticed is that everything works fine when run using the Sun JDK1.3 VM. It is only in my production environment (Lotus Notes) that the problem occurs. It seems the Notes class loader is doing things differently to the sun class loader. Perhaps this is a security issue?
Can anyone shed any light on why this is occuring? Why does everything work fine with one particular Jar (Jakarta POI) but no others I have tried? And why does it stop working in the Notes environment?
Any help is appreciated.
And here is my code:
    public void test()
        URL[] urls=new URL[1];
        File file=new File("c:/software/libraries/tablelayout.jar");
        try
            urls[0]=file.toURL();
        catch (MalformedURLException e)
            e.printStackTrace();
            return;
        ClassLoader cl = this.getClass().getClassLoader();
        ClassLoader loader=URLClassLoader.newInstance(urls,cl);
        Class agentClass=null;
        try
            // Test if we can actually load the class
            Class testClass = loader.loadClass("com.lowagie.text.pdf.PdfReader");
            System.out.println("loaded test class");
            agentClass = loader.loadClass("test.RandomAgent");
        catch (ClassNotFoundException e)
            e.printStackTrace();
            return;
        AgentBase agent=null;
        try
            agent = (AgentBase) agentClass.newInstance(); // This is where the NoClassDefFoundError is thrown
        catch (Exception e)
            e.printStackTrace();
            return;
        agent.NotesMain();
    }And the stack trace I get:
loaded test class
java.lang.NoClassDefFoundError: com/lowagie/text/pdf/PdfReader
     at java.lang.Class.newInstance0(Native Method)
     at java.lang.Class.newInstance(Class.java:262)
     at TestAgentUsingClassLoader.NotesMain(TestAgentUsingClassLoader.java:64)
     at lotus.domino.AgentBase.runNotes(Unknown Source)
     at lotus.domino.NotesThread.run(NotesThread.java:218)

I figured it out. Thanks to this post: http://forum.java.sun.com/thread.jspa?threadID=484866&messageID=2267796
The class test.RandomAgent was actually being loaded by the system classloader, even though I had asked to create it using the URLClassLoader. The URLClassLoader delegates the creation to its parent (the system class loader) which found the test.RandomAgent class on the system class path. Thereon, all class created by the RandomAgent class would have been loaded by its ClassLoader, i.e. the system class loader.
To fix this, I had to ensure the test.RandomAgent class was not on the system classpath. To do that, I had to put it in its own Jar and add that jar to the URLClassLoader list.
It turned out that the reason it worked with one jar (Jakart POI) was that that Jar was on my system classpath! So that was a red herring.

Similar Messages

  • Class Loader Hierarchy in Weblogic 7.0

    I have read the BEA documentation on the class loader hierarchy in Weblogic Server,
    and I have some questions regarding some behavior I am seeing.
    I am running Weblogic Server 7.0.
    I have an ear file that contains 3 web apps (wars) and several utility jars. The
    web apps' manifests contain the Class-Path entry for the utility jars. My understanding
    of this is that each web app SHOULD have its own class loader. Also, the utility
    jars will be scoped in a separate class loader and WILL NOT have visibility to
    the web app classes. The web app classes should have visibility to the utility
    jars.
    Is this correct????
    I added a static segment of code in each web app and printed the class loader
    for each servlet when it was loaded. I also printed the class loader from a class
    that is DEFINITELY contained in one of the utility jars. Here is the result:
    Utility Class ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Utility Class
    Parent ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    Servlet 1 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet 1 Parent
    ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    Servlet 2 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet 2 Parent
    ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    I'm a little confused.... I expected to see 3 different class loaders (i.e. one
    for each class above). I believe the above printout says that all 3 classes are
    being loaded by the SAME class loader instance (Launcher$AppClassLoader@b9d04).
    Am I interpreting this correctly? If so, what's going on?

    I rechecked the classpath for the user that starts Weblogic, and in the classpath
    I found the project "src" directory (must have missed it earlier). When we did
    our build, the classes are placed in the src structure then copied to the build
    area. That's the reason I was not seeing the appropriate class loader hierarchy.
    Thanks for all of the comments.
    "Sanjeev Chopra" <[email protected]> wrote:
    >
    "Mark Cotherman" <[email protected]> wrote in message
    news:[email protected]...
    Thanks for your comments again Mark. I'm just trying to get a goodhandle
    on how
    this is working.
    I'll assume that somehow my web app classes are being loaded into theroot
    classloader.
    The next question is... why??Just to be sure - is there any way these classes are sneaking into the
    system classpath ?
    My ear file contains the following:
    a.war
    b.war
    c.war
    lib/util1.jar
    lib/util2.jar
    lib/util3.jar
    lib/util4.jar
    The manifest in all three wars reference all util jars. This ear deployssuccessfully
    on Weblogic with no errors.
    How could these separate servlets (one in each war) not have seperateclass loaders
    seperate from the root where the utils should reside. I don't thinkthat
    I have
    any control over where Weblogic loads the war classes, or do I?
    See comments below....
    Mark Spotswood <[email protected]> wrote:
    Mark Cotherman wrote:
    Thanks for the follow-up.
    I want to make sure I follow what you are saying. All classes in
    the
    manifest
    Class-Path of WARs are exported to the parent classloader.That's right.
    To me this is the correct behavior since the manifest Class-Path
    is
    meant to provide
    a way to share common utility classes among several web apps. AllEJB jars and
    manifest Class-Path entries should be loaded by the same class loader.Its a way to share class definitions, but not necessarilly class
    instances. I don't think that a web application should be extending
    the classpath of its parent's classloader. This leads to namespace
    problems as well as reloadability issues.
    Ok, you lost me here. Shouldn't delegation handle the namespacecollisions??
    If the web app class loader has a class definition (webapp:com.xyz.ClassA) with
    exactly the same name in the same package as the root class loader(rootloader:
    com.xyz.ClassA), I thought the web app would use (delegate loading)the
    class
    definition from the root class loader when PreferWebInf is set to false.
    Isn't this why the PreferWebInf attribute, when set to true, can causeClassCastExceptions??
    The web app when creating an instance of (webapp: com.xyz.ClassA)from
    the web
    app class loader can potentially pass a reference to this instanceto a
    class
    instance loaded from the root loader. The root class loader has adifferent class
    definition for ClassA.
    REALLY what makes since is that all common jar files be defined
    in
    the manifest
    Class-Path OF THE ear FILE (if the WAR(s) are in an ear). These
    jar
    files should
    then be loaded by the same class loader as the EJB jars. There shouldbe no need
    for the WARs to have any reference to the utility jars since the
    EJB
    class loader
    is the parent of the WAR class loaders.The ear file doesn't have a manifest classpath, but what you are getting
    at makes sense. If you add a manifest to any EJBs in your app, theall
    webapps (as well as all other EJBs) will be able to see it, sincewith
    our structure, EJBs are loaded into the application's root classloader.
    My problem is that the ACTUAL SERVLET classes are NOT being loadedby a separate
    class loader from the EJB and common jar class loader. This is
    completely
    against
    what is being said in the Weblogic documentation. The Manifest
    Class-Path
    should
    have nothing to do with where the classes that reside in
    WEB-INF/classes
    of my
    servlet are loaded.Classloaders will ask their parent for the class first before loading
    it
    themselves. So if the parent classloader somehow has visibility to
    classes that your webpapp references, then it will get loaded by the
    parent classloader.
    I am in the middle of migrating an app from an older version of
    Weblogic,
    and
    it would be helpful to have the ACTUAL class loading hierarchy welldocumented.
    The basic hierarchy is all EJBs are in a root shared classloader and
    each web application is loaded by a classloader that is a child of
    that root.
    Again, am I missing something here???My suspicion is that somehow these servlets are in the classpath ofthe
    root classloader, so when the webapp classloaders delegate to thatone,
    it will come up with the class.
    mark
    Mark Spotswood <[email protected]> wrote:
    I believe what you are seeing is a bug in the servlet container.
    The classloader organization is what you expect, but each webapp
    is exporting the classpath information from its manifest to the
    classloader above its classloader (which is common to all
    three webapps) rather than to its own classloader. So because
    of the delegation that happens with classloading, the common
    parent classloader is the one that loads the class.
    I believe that this behavior exists as an attempt to avoid
    ClassCastExceptions, but I don't think that it is the right
    solution to this problem. In our 8.1 release, this behavior
    has been changed. That is, web applications no longer export
    manifest classpath information to the parent of their classloader.
    This change has not been ported back to the 7.x line, but a bug
    report has been created (CR099889). You should be able to follow
    up with support with this CR number.
    mark
    Mark Cotherman wrote:
    I have read the BEA documentation on the class loader hierarchy
    in
    Weblogic Server,
    and I have some questions regarding some behavior I am seeing.
    I am running Weblogic Server 7.0.
    I have an ear file that contains 3 web apps (wars) and several
    utility
    jars. The
    web apps' manifests contain the Class-Path entry for the utility
    jars.
    My understanding
    of this is that each web app SHOULD have its own class loader.
    Also,
    the utility
    jars will be scoped in a separate class loader and WILL NOT have
    visibility
    to
    the web app classes. The web app classes should have visibility
    to
    the utility
    jars.
    Is this correct????
    I added a static segment of code in each web app and printed the
    class
    loader
    for each servlet when it was loaded. I also printed the class loaderfrom a class
    that is DEFINITELY contained in one of the utility jars. Here is
    the
    result:
    Utility Class ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04
    Utility
    Class
    Parent ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    Servlet 1 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet1 Parent
    ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    Servlet 2 ClassLoader: sun.misc.Launcher$AppClassLoader@b9d04 Servlet2 Parent
    ClassLoader: sun.misc.Launcher$ExtClassLoader@71732b
    I'm a little confused.... I expected to see 3 different class loaders(i.e. one
    for each class above). I believe the above printout says that all
    3
    classes are
    being loaded by the SAME class loader instance
    (Launcher$AppClassLoader@b9d04).
    Am I interpreting this correctly? If so, what's going on?

  • Weblogic Class Loader issues.

    Hi all!
    Let me explain my problem.
    I have an EJB which has in its same Java package some support classes
    & also a startup class. I created an EJB jar file (containing the home,
    remote, bean, the deployment descriptors & the container generated stubs)
    for deployment. I also compiled all the support classes & the startup class
    into the /weblogic/myserver/serverclasses directory. I also added the
    required entries in the weblogic.properties file for the startup class.
    Now the problem is that the support classes & the startup class contain
    methods & constructors which have package level access (i.e the default
    access in Java). At runtime, when my bean tries to access one of these
    methods, an IllegalAccessException is thrown.
    I understand that this exception is thrown when one tries to access a
    method which should not be accessed (like private/protected/cross-package
    access). However, both the EJB & these classes are in the same package.
    So this should not be thrown.
    Now the next thing I thought is that the EJB & the support classes are
    being loaded by 2 different classloaders. I guess the classes under
    /weblogic/myserver/serverclasses are being loaded by the WebLogic
    Server ClassLoader & the EJB bean classes are being loaded by the
    specialized EJB ClassLoader.
    Now my question is,
    1) Is it the case that the WebLogic Server does not recognize that the
    EJB Bean class is in the same package as the support classes because
    they are loaded by 2 separate class loaders? Please note that the EJB
    jar file does not contain any support classes - so there is no
    duplicate classes here.
    2) Is this a bug?
    3) What should I do to prevent this problem?
    Some workarounds that I have done are:
    1) Copied the Bean.class (implementation class of EJB bean) into the
    serverclasses directory. Now the server does not throw any
    IllegalAccessException. -- This, however, does not appeal as a solution
    since it looks like the Bean class is now being loaded by the WebLogic
    Class Loader instead of from the EJB jar file.
    2) I changed all the default package access methods to public methods.
    Works like a charm. -- Problem is that this is a third party set of classes
    which I would like to avoid modifying.
    Hope this is not too confusing. Please let me know if you need any further info.
    Thanks much in advance,
    --Das

    You have to tell WLAS where to load your new classes. You can change
              workingDir of your JSP configuration in weblogic.properties to point to your
              new class directory.
              Cheers - Wei
              Hyung-Jin Kim <[email protected]> wrote in message
              news:[email protected]..
              > It seems that if I compile a class that a JSP uses while Weblogic is
              > running, Weblogic's class loader has this nasty habit of caching/writing
              > the class that already has loaded into memory into:
              >
              > weblogic/myServer/classfiles
              >
              > Weblogic then refers to the older class file under the above directory
              > when the server is started again. Is there any way to turn this "class
              > loader caching" off in Weblogic? Thanks!
              >
              > -hjk
              >
              

  • Orion-web.xml -- web-app-class-loader

    Hi all, I posted this in the jDeveloper section and someone suggested that I ask you guys what the importance of the orion-web.xml file is. Currently my files looks like ...
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE orion-web-app PUBLIC "-//Evermind//DTD Orion Web Application 2.3//EN" "http://xmlns.oracle.com/ias/dtds/orion-web.dtd">
    <orion-web-app servlet-webdir="/servlet/">
    </orion-web-app>
    But it keeps adding the line that I mention below...
    I have a system that consists of multiple projects. When I deploy all projects they all work fine except for one. We discovered that this is due to the following line in the orion-web.xml file in that project ....
    <web-app-class-loader search-local-classes-first="true"/>
    I removed that line and everything is now fine. However, whenever I open up the application in jDev is puts that line back (even if I don't make changes).
    Is there a setting somewhere that is forcing this line to be put there and, if so, why? And how do I switch it off?
    Thanks,
    Russell

    Hey Steve,
    I must admit that this post confused me a bit.
    I can find no deployment plan editor. We have a WAR Deployment Profile, an EAR Deployment Profile and an EJB JAR Deplyment Profile.
    I use the debug functionality (using the embedded OC4J) to test the application locally during development and then deply the EAR Deployment Profile to an EAR file which then gets deployed using an Application Server.
    Further to this I have tried deleting the file (from everywhere), changing the EAR Deployment Properties and even changing the code within the ORION-WEB.XML to say <web-app-class-loader search-local-classes-first="false"/> all to no avail.
    If I remove the file completed, it add its back when I reopen the project. If I change it to false, it changes it back to True.
    Very confused I must admit.
    Thanks,
    Russell

  • Class loader & instantiate

    hi there;
    i know the concept of class loader & instantiate working. may i know, what is the best situation to use <class loader> or <instantiate> method? i am currently being confused by this method. appreciate if you can give scenario to describe?
    thanks in advance.
    rgds;
    yoke yew

    http://java.sun.com/docs/books/tutorial/java/concepts/index.html

  • Help! -- different class loader issue

    From within an EJB I am trying to cast a serializable object, that was passed into this EJB, to its original type. The process ended with a ClassCastException, even though I have double checked that the object being casted is of the correct type and fully qualified package path. It turns out that the problem is caused by the involvment of 2 different class loaders -- The class loader that loads the object is not the same one that loads the EJB doing the casting. The thing that confuses me the most is that this program used to work fine without the exception when it was running in an older environment. Is this a VM issue? Do we have control over what class loader to use when load certain classes/objects? What's the fix to the problem?
    Please help!
    Thanks in advance.
    Lifeng

    It is a Java platform version issue. Since Java 2 The classloaders are lay out in a hierarchy. You can read about it in the public chapters of the book "Inside the Java 2 Virtual Machine" by Bill Venners at
    www.artima.com
    This may be helpful for you . It specifies the class loaders used by a thread to load subsequent classes: aThread.setContextClassLoader(aClassLoader)
    Other soulution is to have the object and EJB being loaded by the same class loader, which could be a common parent class loader for the ones that in your code are actually asked to load these objects
    Otherwise, java.lang.reflect can deal with objects whose type is not known by the compiler.

  • 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 ..

  • Error building project using kXML2 - "Class loading error: Wrong name"

    Hi,
    I'm testing the XML-Parser KXML2 and downloaded the latest package, but the minimal version (kxml2-min.zip). I put this file into the directory "%j2mewtk%\apps\KxmlTest\lib" and wrote the lines
    import org.kxml2.io.*;
    import org.xmlpull.v1.*;
    When I try to build the project with the Wireless Toolkit (v1.04) it spits out the following error:
    Error preverifying class kxml2.io.KXmlParser
    Class loading error: Wrong name
    com.sun.kvem.ktools.ExecutionException: Preverifier returned 1
    Build failed
    I also tried the full package "kxml2.zip" but the same error occurs.
    How can I get rid of this? Thanks in advance!

    Okay, finally worked it out (hopefully). I unpacked the archive to a directory (say "%J2MEWTK%\apps\KxmlTest\tmpclasses") and then preverified them "manually":
    %J2SDK%\bin\preverify.exe -classpath "%J2MEWTK%\apps\KxmlTest\tmpclasses";"%J2MEWTK%\lib\midpapi.zip" org.kxml2.io.KXmlParser
    %J2SDK%\bin\preverify.exe -classpath "%J2MEWTK%\apps\KxmlTest\tmpclasses";"%J2MEWTK%\lib\midpapi.zip" org.xmlpull.v1.XmlPullParser
    %J2SDK%\bin\preverify.exe -classpath "%J2MEWTK%\apps\KxmlTest\tmpclasses";"%J2MEWTK%\lib\midpapi.zip" org.xmlpull.v1.XmlPullParserException
    Then I packed them again to a jar-file:
    %J2SDK%\bin\jar.exe -cvf kxml2-min.jar %J2MEWTK%\apps\KxmlTest\tmpclasses\output\.
    That was all!

  • Performance issues with class loader on Windows server

    We are observing some performance issues in our application. We are Using weblogic 11g with Java6 on a windows 2003 server
    The thread dumps indicate many threads are waiting in queue for the native file methods:
    "[ACTIVE] ExecuteThread: '106' for queue: 'weblogic.kernel.Default (self-tuning)'" RUNNABLE
         java.io.WinNTFileSystem.getBooleanAttributes(Native Method)
         java.io.File.exists(Unknown Source)
         weblogic.utils.classloaders.ClasspathClassFinder.getFileSource(ClasspathClassFinder.java:398)
         weblogic.utils.classloaders.ClasspathClassFinder.getSourcesInternal(ClasspathClassFinder.java:347)
         weblogic.utils.classloaders.ClasspathClassFinder.getSource(ClasspathClassFinder.java:316)
         weblogic.application.io.ManifestFinder.getSource(ManifestFinder.java:75)
         weblogic.utils.classloaders.MultiClassFinder.getSource(MultiClassFinder.java:67)
         weblogic.application.utils.CompositeWebAppFinder.getSource(CompositeWebAppFinder.java:71)
         weblogic.utils.classloaders.MultiClassFinder.getSource(MultiClassFinder.java:67)
         weblogic.utils.classloaders.MultiClassFinder.getSource(MultiClassFinder.java:67)
         weblogic.utils.classloaders.CodeGenClassFinder.getSource(CodeGenClassFinder.java:33)
         weblogic.utils.classloaders.GenericClassLoader.findResource(GenericClassLoader.java:210)
         weblogic.utils.classloaders.GenericClassLoader.getResourceInternal(GenericClassLoader.java:160)
         weblogic.utils.classloaders.GenericClassLoader.getResource(GenericClassLoader.java:182)
         java.lang.ClassLoader.getResourceAsStream(Unknown Source)
         javax.xml.parsers.SecuritySupport$4.run(Unknown Source)
         java.security.AccessController.doPrivileged(Native Method)
         javax.xml.parsers.SecuritySupport.getResourceAsStream(Unknown Source)
         javax.xml.parsers.FactoryFinder.findJarServiceProvider(Unknown Source)
         javax.xml.parsers.FactoryFinder.find(Unknown Source)
         javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
         org.ajax4jsf.context.ResponseWriterContentHandler.<init>(ResponseWriterContentHandler.java:48)
         org.ajax4jsf.context.ViewResources$HeadResponseWriter.<init>(ViewResources.java:259)
         org.ajax4jsf.context.ViewResources.processHeadResources(ViewResources.java:445)
         org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:193)
         org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
         org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
    On googling this seems to be an issue with java file handling on windows servers and I couldn't find a solution yet. Any recommendation or pointer is appreciated

    Hi shubhu,
    I just analyzed your partial Thread Dump data, the problem is that the ajax4jsf framework ResponseWriterContentHandler triggers internally a new instance of the DocumentBuilderFactory; every time; triggering heavy IO contention because of Class loader / JAR file search operations.
    Too many of these IO operations under heavy load will create excessive contention and severe performance degradation; regardless of the OS you are running your JVM on.
    Please review the link below and see if this is related to your problem.. This is a known issue in JBOSS JIRA when using RichFaces / ajaxJSF.
    https://issues.jboss.org/browse/JBPAPP-6166
    Regards,
    P-H
    http://javaeesupportpatterns.blogspot.com/

  • How can I make server use single class loader for several applications

    I have several web/ejb applications. These applications use some common libraries and should share instances of classes from those libraries.
    But applications are being deployed independently thus packaging all them to EAR is not acceptable.
    I suppose the problem is that each application uses separate class loader.
    How can I make AS use single class loader for a set of applications?
    Different applications depend on different libraries so I need a way that will not share library for all applications on the domain but only for some exact applications.
    When I placed common jar to *%domain%/lib* - all works. But that jar is shared between all applications on the domain.
    When I tried to place common jar to *%domain%/lib/applibs* and specified --libraries* attribute on deploying I got exception
    java.lang.ClassCastException: a.FirstDao cannot be cast to a.FirstDaoHere http://download.oracle.com/docs/cd/E19879-01/820-4336/6nfqd2b1t/index.html I read:
    If multiple applications or modules refer to the same libraries, classes in those libraries are automatically shared.
    This can reduce the memory footprint and allow sharing of static information.Does it mean that classes should be able to be casted ?

    You didn't specify which version of the application server you are using, but the config is similar as long as you know what to look for. Basically, you need to change the classloader delegation. Here's how it is done in 8.2
    http://download.oracle.com/docs/cd/E19830-01/819-4721/beagb/index.html

  • How can I get a dynamic list of Classes Loaded

    I assume this may need to use some sort of reflection. Does
    anyone have code or ideas where I can:
    a) I can get a list of all Classes loaded and their
    properties. This would probably be all instances of Class
    b) A list of all
    global instance variables. (This may not even be possible. I
    know it can be done in other languages)
    I assume this may need to use some sort of reflection.
    Thank you

    Adobe Newsbot hopes that the following resources helps you.
    NewsBot is experimental and any feedback (reply to this post) on
    its utility will be appreciated:
    mx.controls.List (Flex 3):
    If the data is incorrect, you can call the preventDefault()
    method to stop Flex from passing the new data back to the list
    control and from closing the
    Link:
    http://livedocs.adobe.com/flex/3/langref/mx/controls/List.html
    Displaying icons in a Flex List control at Flex Examples:
    http://blog.flexexamples.com/2007/08/17/displaying-icons-in-a-flex-list-control/
    --> <mx:Application xmlns:mx=&quot;
    http://www.adobe.com/2006/mxml&quot;
    Link:
    http://blog.flexexamples.com/2007/08/17/displaying-icons-in-a-flex-list-control/
    Populate the list -- Flex 2.01:
    You populate a list-based form control with the
    <mx:dataProvider> child tag. The <mx:dataProvider> tag
    lets you specify list items in several ways.
    Link:
    http://livedocs.adobe.com/flex/201/html/tutorial_controls_019_4.html
    Smooth Scroll for Horizontal List - Flex India Community |
    Google:
    I have created image gallery with Horizontal List[Flex 2.0].
    Just as below ref site. My Problem is i need a smooth scroll for
    Horizontal List. where images
    Link:
    http://groups.google.com/group/flex_india/browse_thread/thread/a12441143b98d32c?hide_quote s=no
    Creating a List control -- Flex 2.01:
    The following example code adds a handler for a change event
    to the List control. Flex broadcasts a mx.ListEvent.CHANGE event
    when the value of the control
    Link:
    http://livedocs.adobe.com/flex/201/html/dpcontrols_062_03.html
    Disclaimer: This response is generated automatically by the
    Adobe NewsBot based on Adobe
    Community
    Engine.

  • How to write a class loader to solve the class confliction in rt.jar?

    Hello guys:
    The weblogic.jar has the javax.management.*, it is conflict with rt.jar's
    I want to use JMX 1.0 to communicate with weblogic 8.1. The client should be run in the Java 1.5
    It throw
    java.io.InvalidClassException: javax.management.ObjectName; local class incompatible:
    stream classdesc serialVersionUID = -5467795090068647408, local class serialVersionUID = 1081892073854801359
    java.io.InvalidClassException: javax.management.ObjectName; local class incompatible:
    stream classdesc serialVersionUID = -5467795090068647408, local class serialVersionUID = 1081892073854801359I know the reason is java 1.5 has JMX 1.2 in it.
    So how can I program a class loader to load the weblogic.jar classes in? I have tried a lot of code, but failed.
    Is there any sample here?
    I want to use the JMX 1.0 in weblogic.jar at jdk1.5 run time
    Thanks a lot,
    Qiang

    Hello guys:
    The weblogic.jar has the javax.management.*, it is conflict with rt.jar's
    I want to use JMX 1.0 to communicate with weblogic 8.1. The client should be run in the Java 1.5
    It throw
    java.io.InvalidClassException: javax.management.ObjectName; local class incompatible:
    stream classdesc serialVersionUID = -5467795090068647408, local class serialVersionUID = 1081892073854801359
    java.io.InvalidClassException: javax.management.ObjectName; local class incompatible:
    stream classdesc serialVersionUID = -5467795090068647408, local class serialVersionUID = 1081892073854801359I know the reason is java 1.5 has JMX 1.2 in it.
    So how can I program a class loader to load the weblogic.jar classes in? I have tried a lot of code, but failed.
    Is there any sample here?
    I want to use the JMX 1.0 in weblogic.jar at jdk1.5 run time
    Thanks a lot,
    Qiang

  • Dinamyc class loading and jar files

    I'm new to java. I would like to load some plugins in my application (it's going to be packaged as a jar at the end). I managed to find some dinamyc class loading examples but they search for the classes to load in a directory.
    This is the code:
        public static void main(String[] args) {
            File pluginDirectory = new File("src/pluginsreloaded/plugins");
            if (!pluginDirectory.exists()) {            // the plugin directory does not exist
                System.out.println("The plugins directory does not exist!");           
                return;
            FilenameFilter filter = new FilenameFilter() {
                public boolean accept(File dir, String name) {
                    return name.endsWith(".class");
            String[] pluginFiles = pluginDirectory.list(filter);
            for (int i = 0; i < pluginFiles.length; i++) {
                if (pluginFiles.indexOf("$") == -1) {
    System.out.println("Loading: " + pluginFiles[i].substring(0, pluginFiles[i].length() - 6));
    IPlugin plugin = pm.loadPlugin(pluginFiles[i].substring(0, pluginFiles[i].length() - 6));
    System.out.println(plugin.description());
    protected static IPlugin loadPlugin(String name) {
            // Query the plugin list for the plugin
            PluginFactory _plugin = (PluginFactory) pluginList.get(name);
            if (_plugin == null) {          // the plugin is not loaded
                try {
                    Class.forName("pluginsReloaded.plugins." + name);
                    // The plugin makes an entry in the plugin list
                    // when loaded
                    _plugin = (PluginFactory) pluginList.get(name);
                    if (_plugin == null) {
                        return null;
                } catch (ClassNotFoundException e) {
                    System.out.println("Plugin " + name + " not found!");
            return _plugin.create();
        }IPlugin is an interface. I am using netbeans 5.0. The error I get is this:
    Exception in thread "main" java.lang.NoClassDefFoundError: pluginsReloaded/plugins/plugin1 (wrong name: pluginsreloaded/plugins/plugin1)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:164)
            at pluginsreloaded.PluginManager.loadPlugin(PluginManager.java:30)
            at pluginsreloaded.Main.main(Main.java:44)
    Java Result: 1As far as I can see it can't find the class. My question is how can I load the class/where can I find it?
    Thanks.

    You can use the java.util.jar.JarFile class to enumerate the contents of a jar. It's not good practice to search for plugins in this way though. A plugin may well involve serveral classes, which don't all have to be internal. Furthermore its wise to avoid any comitment about the mechaism by which class files are to be fetched. You might want to do it remotely, some time, or load them from a database.
    What seesms to be the standard approach is to put a list of plugin classes into the jar as a text file.
    Plugins for a given purpose usually implement some specified interface, or extend some abstract class to which their objects can be cast once loaded (without this they aren't really much use).
    Say your plugins implment org.myorg.WidgetFactory then you put a list of them, one fully qualified name to a line, in a file or jar entry called META-INF/services/org.myorg.WidgetFactory. You framework picks up all such files from the classpath using ClassLoader.getResources() and loads all the classes whose names if finds, hence you can add new sets of plugins just by adding a new jar or class directory to the class path.

  • 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.

  • Application Class Loader problem calling virtual function

    Hello everyone
    I have run in to very strange behavior of JVM
    I have created a class loader which allows my to load classes from
    jar file, regardless that URLClassLoader supplies this functionality.
    I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
    public interface I {
       public void init();
    public class AAA implements
       public void init(){
    public class BBB extends AAA{
       public void init(){
          //here comes implementation
    }Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
    ByteStreamClassLoader  classLoader =  new ByteStreamClassLoader  ();
    Class cl = classLoader. loadClass(�com.product.BBB�,true);
    I myInterface = cl.newInstance();
    myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
    Can somebody help me what am I doing wrong?
    Class Loader code attached below
      public class ByteStreamClassLoader   extends ClassLoader {
        protected HashMap m_cache = new HashMap();
        public void clearCashe() {
          m_cache = new HashMap();
        private String definePackage(String className) {
          StringBuilder strB = new StringBuilder();
          //Class name must be removed from the URI in order to define a package
          String[] packageArray = className.split("\\.");
          for (int i = 0; i < packageArray.length - 1; i++) {
            strB.append(packageArray).append(".");
    String packageName = strB.toString();
    packageName = packageName.substring(0, packageName.length() - 1);
    if (getPackage(packageName) == null) {
    m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
    definePackage(packageName, null, null, null, null, null, null, null);
    return packageName;
    public synchronized Class loadClass(String name, boolean resolve) throws
    ClassNotFoundException {
    name = name.replaceAll("/", ".").replaceAll(".class", "");
    //Try to locate the Class in cashe
    Class c = (Class) m_cache.get(name);
    //Try to locate the Class in the System Class Loader
    if (c == null) {
    try {
    c = ClassLoader.getSystemClassLoader().loadClass(name);
    catch (Exception ex) {}
    else {
    m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
    //Load the class from byte array
    if (c == null) {
    String resourceName = name;
    if (!resourceName.endsWith(".class")) {
    resourceName = resourceName.concat(".class");
    //Retrieve class byte representation
    if (resourceName.indexOf(".") != -1) {
    resourceName =
    resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
    //Use the ByteStreamClassLoader to load the class from byte array
    byte[] classByteArray = null;
    try {
    classByteArray = getResourceBytes(resourceName);
    catch (IOException ex1) {
    throw new ClassNotFoundException(
    "Could not load class data." + ex1.getMessage());
    m_logger.log(
    Level.FINEST, "Loading class '" +
    name + "' Byte Length: " + classByteArray.length);
    String p = definePackage(name);
    c = defineClass(
    name,
    classByteArray,
    0,
    classByteArray.length,
    ByteStreamClassLoader.class.getProtectionDomain());
    m_cache.put(name, c);
    if (resolve) {
    resolveClass(c);
    return c;

    Hello everyone
    I have run in to very strange behavior of JVM
    I have created a class loader which allows my to load classes from
    jar file, regardless that URLClassLoader supplies this functionality.
    I am using this class loader to load some classes and call their virtual functions. The class diagram looks like that:
    public interface I {
       public void init();
    public class AAA implements
       public void init(){
    public class BBB extends AAA{
       public void init(){
          //here comes implementation
    }Interface I and class AAA are loaded with System Class loader and Class BBB is loaded using my class loader from jar file.
    ByteStreamClassLoader  classLoader =  new ByteStreamClassLoader  ();
    Class cl = classLoader. loadClass(�com.product.BBB�,true);
    I myInterface = cl.newInstance();
    myInterface.init();The problem is that from some unknown reason java class AAA.init() instead of BBB.init().
    Can somebody help me what am I doing wrong?
    Class Loader code attached below
      public class ByteStreamClassLoader   extends ClassLoader {
        protected HashMap m_cache = new HashMap();
        public void clearCashe() {
          m_cache = new HashMap();
        private String definePackage(String className) {
          StringBuilder strB = new StringBuilder();
          //Class name must be removed from the URI in order to define a package
          String[] packageArray = className.split("\\.");
          for (int i = 0; i < packageArray.length - 1; i++) {
            strB.append(packageArray).append(".");
    String packageName = strB.toString();
    packageName = packageName.substring(0, packageName.length() - 1);
    if (getPackage(packageName) == null) {
    m_logger.log(Level.FINEST, "Defining package '" + packageName + "'");
    definePackage(packageName, null, null, null, null, null, null, null);
    return packageName;
    public synchronized Class loadClass(String name, boolean resolve) throws
    ClassNotFoundException {
    name = name.replaceAll("/", ".").replaceAll(".class", "");
    //Try to locate the Class in cashe
    Class c = (Class) m_cache.get(name);
    //Try to locate the Class in the System Class Loader
    if (c == null) {
    try {
    c = ClassLoader.getSystemClassLoader().loadClass(name);
    catch (Exception ex) {}
    else {
    m_logger.log(Level.FINEST, "Class '" + name + "' found in cache");
    //Load the class from byte array
    if (c == null) {
    String resourceName = name;
    if (!resourceName.endsWith(".class")) {
    resourceName = resourceName.concat(".class");
    //Retrieve class byte representation
    if (resourceName.indexOf(".") != -1) {
    resourceName =
    resourceName.replaceAll("\\.", "/").replaceAll("/class", ".class");
    //Use the ByteStreamClassLoader to load the class from byte array
    byte[] classByteArray = null;
    try {
    classByteArray = getResourceBytes(resourceName);
    catch (IOException ex1) {
    throw new ClassNotFoundException(
    "Could not load class data." + ex1.getMessage());
    m_logger.log(
    Level.FINEST, "Loading class '" +
    name + "' Byte Length: " + classByteArray.length);
    String p = definePackage(name);
    c = defineClass(
    name,
    classByteArray,
    0,
    classByteArray.length,
    ByteStreamClassLoader.class.getProtectionDomain());
    m_cache.put(name, c);
    if (resolve) {
    resolveClass(c);
    return c;

Maybe you are looking for

  • Error starting application in WAS 5.0.2.9

    Hi, I been having this problem starting an application server for a while. I verify the SOAP port, everithing. For a little explanation, there are 2 websphere (in different servers, both are aix 4.3.3) all WAS 5.0.2.9 and i create a node, to use only

  • Airport utility 6.1 no longer detects time capsule

    After updating to the latest airport utility version 6.1, by time capsule (2nd gen) and my airport express (1st gen) are no longer found in the interface.  The following message is displayed in the utility bottom section "No configured Airport base s

  • Can't Create an Account because password doesn't work

    Hello, Pretty new to the forum. I have just opened an iChat account and I can't get it to work. I am able to create an account name and then I type in a password. Then the screen comes up and the computer asks me to type in my password....I do and th

  • Problem Following SMP tutorial with SDK 8.1

    I'm attempting to follow the SMP development tutorial but I'm starting with Win SDK 8.1.  Attempting to use convert-moftoprovider fails with missing mofs that are referenced in storagewmi_provider.mof (like msft_filestoragetier.mof).  I don't see the

  • Splitting audio from separate browser tabs or instances to different soundcards

    Hi, I would like to be able to separate the audio being played by flash  media player when there are two tabs playing different streams in  Firefox (or another browser). Frustratingly, Adobe Flash Player doesnt offer any choice of the  sound card to