Custom ClassLoader in startup class

Hi,
Is it possible to use a custom class loader inside a startup class ?
Thank You,
Saman

Pls go through the jav adoc of URLConnection class.
You can set the request method as
Set the method for the URL request, one of:
* GET
* POST
* HEAD
* OPTIONS
* PUT
* DELETE
* TRACE
Not you own choice

Similar Messages

  • Custom Service for Startup classes in SAP Netweaver

    Hi All,
    Can any one please let me know for some custom service in Java which can be used in place of startup class? I want to use it to start the RoleListener which will be registered in the RoleFactory of UMFactory?
    Regards,
    Smriti.

    Hello
    maybe a ServletContextListener could help you
    see [http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContextListener.html] and google for ServletContextListener
    regards franz
    reward points if useful

  • Error when starting opmn with custom startup class

    I'm trying to use jaxb 2.0 classes in my custom oc4j startup class, but when I try to start the container the following error is produced in the logs.
    Exception in thread "OC4J Launcher" java.lang.IllegalAccessError: tried to access class javax.xml.bind.ContextFinder from class javax.xml.bind.JAXBContext
    Can anyone provide some guidance?
    Regards,

    It seems I trying to use jaxb 2.x classes but oas 10.1.3.5 uses jaxb 1.0. Is there anyway to get this to work with jaxb 2.x? The error message I'm receiving now is
    Exception in thread "OC4J Launcher" java.lang.NoSuchMethodError: javax.xml.bind.JAXBContext.newInstance([Ljava/lang/Class;)Ljavax/xml/bind/JAXBContext;
    and if I use the JAXBContext.newInstance("package", this.getClass().getClassLoader());
    I get this:
    javax.xml.bind.JAXBException: Unable to locate jaxb.properties for package mil.usmc.mol.mbeans
    10/02/23 13:03:08 at javax.xml.bind.ContextFinder.searchcontextPath(ContextFinder.java:205)
    10/02/23 13:03:08 at javax.xml.bind.ContextFinder.find(ContextFinder.java:149)
    10/02/23 13:03:08 at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:281)
    Brett

  • Which classloader loads the startup class?

    Hi!
    Which classloader loads the startup and shutdown classes?
    Thx.
    A.

    You're correct.
    Just to be 100% clear, the startup classes defined in config.xml are loaded from the $CLASSPATH, domain/lib (in 9.x) or the JDK extensions directory.
    Startup classes which are defined in the weblogic-application.xml (application-scoped startup classes) can be in the application or in any of the server-wide classpath locations.
    -- Rob
    WLS Blog http://dev2dev.bea.com/blog/rwoollen/

  • Failed to invoke startup class "MyStartup Class"

    Hi,
    I configured StartUpClass.java in Weblogic server through Admin Console . Also I set the required jar files in the classpath of the server in WL_HOME\server\bin\startWLS.cmd.
    This StartUPClass is written to initialize and create the minimum number of objects in the pool, needed for URLConnection using ObjectPooling API.
    I am getting Exceptions while starting the server after deployment of the application. I am pasting the full stack trace.
    <Feb 1, 2007 9:49:55 AM IST> <Info> <WebLogicServer> <BEA-000377> <Starting WebLogic Server with Java HotSpot(TM) Client VM Version 1.4.2_12-b03 from Sun Microsystems Inc.>
    <Feb 1, 2007 9:50:10 AM IST> <Info> <Configuration Management> <BEA-150016> <This server is being started as the administration server.>
    <Feb 1, 2007 9:50:10 AM IST> <Info> <Management> <BEA-141107> <Version: WebLogic Server 8.1 SP4 Mon Nov 29 16:21:29 PST 2004 471647
    WebLogic XMLX Module 8.1 SP4 Mon Nov 29 16:21:29 PST 2004 471647 >
    <Feb 1, 2007 9:50:11 AM IST> <Notice> <Management> <BEA-140005> <Loading domain configuration from configuration repository at D:\bea\user_projects\domains\nessdomain\.\config.xml.>
    <Feb 1, 2007 9:50:15 AM IST> <Notice> <Log Management> <BEA-170019> <The server log file D:\bea\user_projects\domains\nessdomain\myserver\myserver.log is opened. All server side log events will be written to this file.>
    <Feb 1, 2007 9:50:18 AM IST> <Notice> <Security> <BEA-090082> <Security initializing using security realm myrealm.>
    <Feb 1, 2007 9:50:18 AM IST> <Notice> <WebLogicServer> <BEA-000327> <Starting WebLogic Admin Server "myserver" for domain "nessdomain">
    <Feb 1, 2007 9:50:31 AM IST> <Warning> <HTTP> <BEA-101248> <[Application: 'D:\MSM\Workspace\MSM2.0Jan9', Module: 'MSM31']: Deployment descriptor "web.xml" is malformed. Check against the DTD: org.xml.sax.SAXParseException: The content of element type "web-app" must match "(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-role*,env-entry*,ejb-ref*,ejb-local-ref*)". (line 96, column 11).>
    <Feb 1, 2007 9:50:31 AM IST> <Warning> <HTTP> <BEA-101248> <[Application: 'D:\MSM\Workspace\MSM2.0Jan9', Module: 'MSM31']: Deployment descriptor "weblogic.xml" is malformed. Check against the DTD: org.xml.sax.SAXParseException: The content of element type "weblogic-web-app" must match "(description?,weblogic-version?,security-role-assignment*,run-as-role-assignment*,reference-descriptor?,session-descriptor?,jsp-descriptor?,auth-filter?,container-descriptor?,charset-params?,virtual-directory-mapping*,url-match-map?,preprocessor*,preprocessor-mapping*,security-permission?,context-root?,wl-dispatch-policy?,servlet-descriptor*,init-as*,destroy-as*)". (line 23, column 20).>
    <Feb 1, 2007 9:50:35 AM IST> <Critical> <WebLogicServer> <BEA-000286> <Failed to invoke startup class "MyStartup Class", java.lang.ClassNotFoundException: com.helio.msm.ws.util.StartUpClass
    java.lang.ClassNotFoundException: com.helio.msm.ws.util.StartUpClass
         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 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:141)
         at weblogic.t3.srvr.StartupClassService.invokeClass(StartupClassService.java:156)
         at weblogic.t3.srvr.StartupClassService.access$000(StartupClassService.java:36)
         at weblogic.t3.srvr.StartupClassService$1.run(StartupClassService.java:121)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
         at weblogic.t3.srvr.StartupClassService.invokeStartupClass(StartupClassService.java:116)
         at weblogic.t3.srvr.PostDeploymentStartupService.resume(PostDeploymentStartupService.java:63)
         at weblogic.t3.srvr.SubsystemManager.resume(SubsystemManager.java:131)
         at weblogic.t3.srvr.T3Srvr.resume(T3Srvr.java:966)
         at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:361)
         at weblogic.Server.main(Server.java:32)
    >
    <Feb 1, 2007 9:50:36 AM IST> <Error> <Socket> <BEA-000438> <Unable to load performance pack. Using Java I/O instead. Please ensure that wlntio.dll is in: 'D:\j2sdk1.4.2_12\bin;.;C:\WINDOWS\system32;C:\WINDOWS;D:\j2sdk1.4.2_12\bin;c:\windows\system32;C:\apache-ant-1.6.5\bin;'
    >
    <Feb 1, 2007 9:50:36 AM IST> <Notice> <WebLogicServer> <BEA-000331> <Started WebLogic Admin Server "myserver" for domain "nessdomain" running in Development Mode>
    <Feb 1, 2007 9:50:36 AM IST> <Notice> <WebLogicServer> <BEA-000360> <Server started in RUNNING mode>
    <Feb 1, 2007 9:50:36 AM IST> <Notice> <WebLogicServer> <BEA-000355> <Thread "ListenThread.Default" listening on port 7001, ip address *.*>
    <Feb 1, 2007 9:50:55 AM IST> <Warning> <Socket> <BEA-000402> <There are: 5 active sockets, but the maximum number of socket reader threads allowed by the configuration is: 4. You may want to alter your configuration.>
    Please help me in resolving this problem. I need it asap
    Thanks,
    Dharani

    I should be more specific and have a bit more to add....
    We have our app in an .ear file. I find that when I put the startup
    classes in a seperate directory which is in the classpath specified in the
    startWeblogic.cmd file they will be run on startup. I don't think I should
    have to do this since these files exist in the ear file. I think this is
    causing other problems too such as an illegalAccessError I get when an EJB
    tries to load a class which was previously accessed by the startup classes.
    Thanks,
    Steve
    Steve Snodgrass wrote:
    Hi,
    I am beggining to upgrade our app from Weblogic 5.1 to 6.0. So far it
    has been progressing nicely and everything works with one exception. I
    can not get the start up classes to run. I get the following exception:
    <Failed to invoke startup class "MyStartup Class",
    java.lang.ClassNotFoundException:
    followed by my fully qualified class name. The class is reference
    elsewhere in the code and works fine. Is a seperate classpath used for
    startup classes? If not why might Weblogic have a hard time finding my
    class?
    Thanks,
    Steve

  • The struggle of creating a Custom ClassLoader for Native libraries

    Hello Everyone,
    I'm having a really hard time writing and using my own ClassLoader in a Java Applet.
    Context :
    As the this link shows - http://codethesis.com/tutorial.php?id=1 - loading and especially unloading native libraries through Java requires defining our own ClassLoader, and use it to instantiate a class loading a library. When the class using native libraries has finished execution, setting all references to the classloader and calling the garbage collector will cause the native library to be unloaded. The class to load within the custom classloader is thus read byte after byte from the jar and defined using the Classloader.defineClass(..) function. So that's what I did. But I've got two problems.
    Problem 1 :
    On one single machine over 15 tested, the magic number of a given class read from the Jar using Applet.class.getResourceAsStream(classname) takes a value different from CAFEBABE and the defineClass function then throws an "Incompatible magic value" exception (see below). The workaround I found is to force the first 4 bytes of the byte array read from the class with CAFEBABE. But I still would like to understand why it takes a different value on this machine.
    Exception in thread "thread applet-MyApplet.class-1" java.lang.ClassFormatError: Incompatible magic value 409165630 in class file Reader
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at NativeClassLoader.findClass(Unknown Source)
    Problem 2 :
    On windows, the NativeClassLoader works perfectly, but on Linux, I'm getting a java.lang.VerifyError (see below).
    Code is compiled with java 1.6.0_06 on windows XP. I tried to remove everything related to native code (remove .so load), the same error is raised.
    java.lang.VerifyError: (class: Reader, method: <clinit> signature: ()V) Illegal instruction found at offset 1
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    at java.lang.Class.getConstructor0(Class.java:2699)
    at java.lang.Class.newInstance0(Class.java:326)
    at java.lang.Class.newInstance(Class.java:308)
    Code :
    NativeClassReader (custom) :
    public class NativeClassLoader extends ClassLoader {
        //the unique instance of the NativeClassLoader
        private static NativeClassLoader instance;
        private NativeClassLoader () {
            super(NativeClassLoader.class.getClassLoader());
         * Get the Singleton instance of the class
        public static NativeClassLoader getInstance () {
            if (instance == null)
                instance = new NativeClassLoader();
            return instance;
        public static void dispose () {
            instance = null;
         * Load a class using its full java name (prefixed with package)
        public Class findClass (String theName) {
            byte[] b = null;
            try {
                b = loadClassDataFromJar(theName);
                Class clazz = defineClass(theName, b, 0, b.length);
                resolveClass(clazz);
                return clazz;
            } catch (Exception e) {
                return null;
         * Gets the bytes of a class file stored in the current jar using
         * its full class name
        public byte[] loadClassDataFromJar (String theName)
                                     throws Exception {
            String filename = "/" + theName.replace('.', '/') + ".class";
            InputStream is = SawsApplet.class.getResourceAsStream(filename);
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            //compute file size
            Vector vChars = new Vector();
            int c;
            while ((c = br.read()) != -1)
                vChars.add(new Byte((byte) c));
            //fill in byte array with chars read from the buffer
            byte[] buff = new byte[vChars.size()];
            //workaround for a bug on one (some) Vista machine(s)
            //force magic number to CAFEBABE instead of 18635F3E
            if (vChars.size() > 3) {
                buff[0] = (byte) 0xCA;
                buff[1] = (byte) 0xFE;
                buff[2] = (byte) 0xBA;
                buff[3] = (byte) 0xBE;
            for (int i = 4; i < vChars.size(); ++i)
                buff[i] = ((Byte) vChars.get(i)).byteValue();
            return buff;
    }Reader (loading native libary) :
    public class Reader {
       static {
         System.loadLibrary("myLib");
        public static native String getData();
    }Main :
        NativeClassLoader cLoader = NativeClassLoader.getInstance();
        Class clazz = cLoader.findClass("Reader"); // ClassFormatError thrown here
        Object reader = clazz.newInstance(); // VerifyError thrown here
        Method m = clazz.getMethod("getData");
        String s = m.invoke(reader);
        print(s);
        s = null;
        m = null;
        reader = null;
        clazz = null;
        cLoader = null;
        NativeClassLoader.dispose();
        System.gcAny ideas would be really appreciated :-)
    Guillaume

    Are you using the executable exe file and the filename as a parameter in the custom task?
    Andreas Baumgarten | H&D International Group

  • Annotation-Processing Using Custom ClassLoader Fails

    Hi,
    I have the following problem concerning annotations.
    I am using Jaxb2 to marshal some classes and Jaxb relies heavily on processing annotation information contained in them.
    If I put the Jaxb JAR's directly in the classpath everything works fine.
    However, if I use a custom URLClassLoader to load all the Jaxb-related classes the annotation processing fails thus making Jaxb believe that the objects can't be marshaled.
    Note that the classes to marshal containing the annotations to read are loaded with a different ClassLoader which is higher in the hierarchy.
    I tracked down the problems to the class RuntimeInlineAnnotationReader of the Jaxb API which simply calls Class.getAnnotion(..).
    When searching for this bug I also found the bug report 5015623 which relates to this problem. But it is rather outdated, so I hope that there are some better solutions than just ignoring it.
    I wouldn't like having the Jaxb JARs on the global classpath 'cause they are used in only one class out of 100 and thats not worth the possible conflicts with other 3rd party libs.
    Best regards,
    beebop

    No problem, I will give you some details about my architecture.
    First of all I encapsulated the code which uses the Jaxb-API in one class, say Foo, which implements the interface FooInterface.
    Secondly I load the Foo class in another class, Bar, using my derivation of URLClassLoader, called MyClassLoader. Then I use the interface to marshal an object gen of type GenClass where GenClass was generated using xjc:
    class Bar {
      void method(URL[] urls, GenClass gen) {
        ClassLoader parent = Bar.class.getClassLoader();
        ClassLoader myCL = new MyClassLoader(urls,parent);
        Class clazz = myCL.loadClass("Foo");
        FooInterface foo = (FooInterface)clazz.newInstance();
        foo.marshal(gen);
    }So my class loader will be a child of the current class loader. The delegation model of class loading is reversed in MyClassLoader so that first the urls will be checked and then, if the class was not found, the parent class loader.
    Note that GenClass and its ObjectFactory which acutally contain the annotations Jaxb needs will be loaded by the current class loader, not my own. All classes of the Jaxb-API will be loaded by MyClassLoader. If I try to marshal gen, the annotations of the ObjectFactory corresponding to GenClass won't be readable causing the Class.getAnnotation(...) method called in the class RuntimeInlineAnnotationReader to return null.
    If I don't use my own class loader, say
    FooInterface foo = new Foo();everything works fine and the annotations of the ObjectFactory are loaded correctly.
    I observed the different behaviour by stepping through the classes and methods around JaxbContext.newInstance(...).
    MyClassLoader is not that different from URLClassLoader, only the loadClass method is overridden to change the delegation behaviour. Thats why I suspect an error in the annotations framework and not in my class loader but I may be mistaken.
    Best regards,
    beebop

  • XMLEncoder stackoverflow problem with custom classloader

    Hi, All
    I'm tring encoding my object using XMLEncoder, the objects are from the custom classloader like URLClassLoader which is importing several jar files at run-time.
    source code is like this:
    XMLEncoder e = new XMLEncoder(new BufferedOutputStream(os));
    e.writeObject( sourceObj);
    When I run it, I experienced this error:
    XMLEncoder has "ClassNotFoundException" or "InstantiationException" problem.
    so I found very similar posting for this problem and modified it so that the XMLEncoder can find my classes from custom classloader:
    ClassLoader cl = this.getClass().getClassLoader();
    URLClassLoader urlClassLoader = new URLClassLoader(urls, cl);
    Thread.currentThread().setContextClassLoader(urlClassLoader);
    XMLEncoder e = new XMLEncoder(new BufferedOutputStream(os));
    e.writeObject( sourceObj);
    The result was slightly changed. However, still disappointing:
    java.lang.StackOverflowError
         at java.lang.Class.getMethod0(Class.java:1734)
         at java.lang.Class.getMethod(Class.java:951)
         at java.beans.Statement.findPublicMethod(Statement.java:230)
         at java.beans.Statement.findMethod(Statement.java:270)
         at java.beans.Statement.getMethod(Statement.java:366)
         at java.beans.Statement.invoke(Statement.java:439)
         at java.beans.Expression.getValue(Expression.java:101)
         at java.beans.Encoder.getValue(Encoder.java:84)
         at java.beans.Encoder.get(Encoder.java:186)
         at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:97)
         at java.beans.Encoder.writeObject(Encoder.java:55)
         at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
         at java.beans.Encoder.writeExpression(Encoder.java:260)
         at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
         at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
         at java.beans.Encoder.writeObject(Encoder.java:55)
         at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
         at java.beans.Encoder.writeExpression(Encoder.java:260)
         at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
         at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
         at java.beans.Encoder.writeObject(Encoder.java:55)
         at java.beans.XMLEncoder.writeObject(XMLEncoder.java:250)
         at java.beans.Encoder.writeExpression(Encoder.java:260)
         at java.beans.XMLEncoder.writeExpression(XMLEncoder.java:351)
         at java.beans.PersistenceDelegate.writeObject(PersistenceDelegate.java:100)
         at java.beans.Encoder.writeObject(Encoder.java:55)
    When I finally include the jar files into the classpath so that the default classloader can reference them, the encoder worked properly.
    Anyone can help me?

    StackOverFlow is quite a gotcha in XMLEncoder it is often because of the following code in java.beans.PersistenceDelegate:
    public void writeObject(Object oldInstance, Encoder out) {
    Object newInstance = out.get(oldInstance);
    if (!mutatesTo(oldInstance, newInstance)) {
    out.remove(oldInstance);
    out.writeExpression(instantiate(oldInstance, out));
    else {
    initialize(oldInstance.getClass(), oldInstance, newInstance, out);
    and the following code in java.beans.DefaultPersistenceDelegate:
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
    // Assume the instance is either mutable or a singleton
    // if it has a nullary constructor.
    return (constructor.length == 0) || !definesEquals(oldInstance) ?
    super.mutatesTo(oldInstance, newInstance) :
    oldInstance.equals(newInstance);
    What this means is if you have a class (you want to persist) that has a constructor that takes arguments AND defines an equals method AND you have overridden initialize in DefaultPersistenceDelegate to do some extra work after it instantiates newInstance, then while the PersistenceDelegate is trying to generate you newInstance, oldInstance.equals(newInstance) will return false, and PersistenceDelegate will keep trying to instantiate a newInstance that does equal the oldInstance.
    So if you do use DefaultPersistenceDelegate then ensure that you override mutatesTo so that it is:
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
    return (newInstance != null && oldInstance.getClass() == newInstance.getClass());
    Here is an example PersistenceDelegate that persistence a class called PersistentBeanCollection, it calls its constructor with the property "type" and then calls the method add() on the newInstance.
    new DefaultPersistenceDelegate(new String[]{"type"}) {
    protected void initialize(Class type, Object oldInstance, Object newInstance, Encoder out) {
    PersistentBeanCollection oldBeanCollection = (PersistentBeanCollection) oldInstance;
    for (Iterator iterator = oldBeanCollection.iterator(); iterator.hasNext();) {
    out.writeStatement(new Statement(oldInstance, "add", new Object[]{iterator.next()}));
    protected boolean mutatesTo(Object oldInstance, Object newInstance) {
    return (newInstance != null && oldInstance.getClass() == newInstance.getClass());
    Cheers
    Parwy

  • Best way to call custom classloader

    I have created a custom classloader to perform hot deployment for application server. How do I let JVM to use my class loader instead of system class loader?
    a. Using the command line argument -Djava.system.class.loader
    b. Using -javaagent and setting System.setProperty("java.system.class.loader", myclass) in premain method.
    c. Is there any other alternative?
    If I am using the command line approach, I will need to have my jar file in the classpath. What is the best way to do this?
    Thanks for your help

    Or you could write a small program which sets up the classloader and then loads the target program with it.

  • Customer ClassLoader:  keeping JWS from loading jars

    I really like the ability of JWS to be able to download jars required for my application to run, but there are several jars that I need the ability to load up via a custom ClassLoader. But because JWS includes all of these jars in the classpath upon application start, the system class loader will take the first class it can find. Because I need to load classes from these jars based upon something a user selects, I need to have control over the codesource for these classes. Does anyone have any ideas on how to tackle this problem? Not include the jars in the jnlp and then download if not cached locally, if that's the case what's the best way to do that? Include in jnlp and be able to load with custom classloader(I dont think this will work)? Any ideas on this would greatly be appreciated.

    Easiest solution to your problem and still being able to use the update mechanism of JWS is to include your JAR-file in another JAR-file that JWS loads, and then write up your own classloader, which tries to fetch your JAR-file from the downloaded JAR-file (if JWS already downloaded it, otherwise JWS will download it).
    The contents of the jws-stub.jar would be something
    of the following ;).
    jws-stub.jar
    --> myjar1.jar
    --> myjar2.jar
    org.myjar.MyJarClassloader
    Then based on your user selecting something you
    can decide which JAR-file you want to load, and thus
    which class.
    Hope this helped,
    Manfred.

  • Custom ClassLoader - trying to use different version of SNMP library than WebLogic Server 8.1 uses

    Problem: my J2EE ear file uses the AdventNet third-party library to do
    SNMP work. WebLogic Server 8.1 also uses this AdventNet third-party
    library to do its own SNMP work. The problem is the version used by
    WebLogic 8.1 is older than the version I use, so my code tries to run
    and finds the wrong version of the library that WebLogic 8.1 has supplied.
    Possible solution: I plan to have a custom classloader (derived from
    java.lang.ClassLoader) that gets hooked in to my threads using
    Thread.setContextClassLoader(). This custom classloader would look for
    the AdventNet library jars in a spot I specify so it would find the
    correct ones. Since I want to change the usual classloader behavior of
    "look in parent classloaders first, then child classloader" to "look in
    child classloader first, then in parent classloaders" I can't just
    override ClassLoader.findClass(). I, at a minimum, have to override
    ClassLoader.loadClass() to look in my classloader first. I have
    questions about this:
    1. What other methods do I have to override? For example, which of the
    resource-related methods do I need to override so that resources are
    searched for first in my classloader then in parent classloaders?
    2. I was thinking of using a URLClassLoader as a helper to my
    classloader, invoking its method(s) from my custom classloader's
    method(s) to actually load the classes from URLs that are not on the
    standard classpath. I was planning to set it up with a custom parent
    classloader that can't find anything, so that the helper URLClassLoader
    would only ever find classes/resources in the URLs I provide to it. Does
    this approach make sense? Have you seen anything like this done before?
    3. Is there any way around this problem besides a custom ClassLoader? A
    buggy custom ClassLoader would have problems which AFAIK would be
    difficult to track down as ClassLoader problems.
    Thanks in advance for any help you can provide.

    Alvin wrote:
    Hi,
    I am experiencing the same problme and
    even I tried to put the AdventNet jar files
    before weblogic.jar I still cannot get it
    to work
    Would you help me out here.
    Thanks,
    -AlvinI finally figured out a way to do it using a custom classloader that
    looked in the directory where I kept the version of AdventNet I wanted
    before looking in the normal places classloaders look.
    How it works is I hook two classloaders at the bottom of the chain of
    classloaders. My custom BlockingClassLoader is hooked as a child of the
    normal chain of classloaders, then a URLClassLoader is hooked under
    that. The BlockingClassLoader's findClass method checks if the class
    starts with a package prefix I want to control (like "com.adventnet.").
    If it does, then it acts like it can't find the class. This makes its
    child, the URLClassLoader, try to find the class. The URLClassLoader
    is given the URL of places to look for classes that match the directory
    I keep the version of AdventNet I want in. When I load a class, I
    directly tell the URLClassLoader to load it so that it is loaded as I want.
    There's more to it than this. I had to override some other methods in
    my BlockingClassLoader and do some other stuff. I'm not sure if I can
    share the source code, as it was developed on company time and thus is
    owned by the company. Feel free to ask questions though.
    I haven't tried this solution very long (basically just unit tested it)
    but it looks promising.

  • Custom ClassLoader

    I do not understand much how to create a simple custom class loader. I found many explaination about it. I don't really get what it means.
    Can anyone explain to me in simple code? My custom classloader doesn't work at all.
    I want to load a class in another package. How can I do it?
    Thanks

    What do you mean by "package"?

  • Custom classloader in Applet?

    Hi
    I have for some time tried to load an Applet from within an Applet by means of custom classloader.
    However when reading various specifications for classloader they state it is not possible for an Applet to do so.
    Does anyone know otherwise?

    Hi
    To be more specific.. I have 2 Applets yes. In the first signed Applet I run as a jar I have created a custom classloader that extends ClassLoader hence the java bytecode I wish to load (also an Applet) must be (a) class file(s). As far as I know the ClassLoader is not able to define classes from jars right?
    It is only the loading Applet that is packed as a jar and there is no nested jars. However the loaded Applet is now loaded as a class file but I would like to load is a jar for speeding up loading time.
    Quote from http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html:
    There is a cost, however, because the class loader is so powerful (for example, it can replace java.lang.Object with its own version), Java classes like applets are not allowed to instantiate their own loaders. (This is enforced by the class loader, by the way.) This column will not be useful if you are trying to do this stuff with an applet, only with an application running from the trusted class repository (such as local files).

  • Problem with startup classes

    Hi,
    I am using a custom connection pool to make database connection.I have a
    start up class in which i am initialising the connection pool.This part
    works fine at the time of start up of the server.
    But, when i run my application which is trying to access the database , i am
    unable to get handle to the above created pool.
    Is this because of two different classloaders being used for start up
    classes and web application?
    If so, what could be the possible solution?If anybody knows please let me
    know.

    1. use jndi to register and locate your resource.(connection pool). this
    could be one solution
    2. Instead load thru' your startup class a file prop file wherein you tell
    weblogic the name and property of the coonection pool. Use these properties
    to create a connection pool.
    3. There is a connection API within weblogic to write java code to create
    your connection pool.
    Hope these things helps.
    Chandra
    "makkineni" <[email protected]> wrote in message
    news:3a8afc20$[email protected]..
    Hi,
    I am using a custom connection pool to make database connection.I have a
    start up class in which i am initialising the connection pool.This part
    works fine at the time of start up of the server.
    But, when i run my application which is trying to access the database , iam
    unable to get handle to the above created pool.
    Is this because of two different classloaders being used for start up
    classes and web application?
    If so, what could be the possible solution?If anybody knows please let me
    know.

  • Customized ClassLoader

    Can anyone tell me how to write a customized Classloader which can create an instance of any class other than the one stated in the code.
    like, in
    Socket s = new Socket ();
    rather than creating an instance of Socket class, if I want to create instance of any other class, how can I do that?
    -Rohit

    Can anyone tell me how to write a customized
    Classloader which can create an instance of any class
    other than the one stated in the code.Sorry, this can't be done just by writing your own class loader. You would need to tweak the JVM or bytecode.
    It also depends on what you mean by "any other class". If you want to load a modified version of the same class, then along the bytecode route, AspectJ might be able to do the job. There may be other bytecode post-processors that can help as well.
    Exactly what class do you plan on substituting? If you don't know already, any program will fail miserably if the classes loaded behave substantially differently than what was expected.

Maybe you are looking for

  • Transport issue - Objects being picked diffrently in Dev system

    Hello folks, We added some new custom fields to our 2lis_02 datasource and replicated the datasource into the BW side. Mapped the new objects in transfer rules and activate, when it prompts me for the transport and I give it a number it gives me an e

  • Import date added

    hi all, i just bought a new macbook and after i imported all of my songs from my old windows itunes library, i lost all of the dates added. i'd love to be able to import the dates along with the songs but have not found a way. please help. thanks.

  • Final Cut Pro ProRes Rendering

    I have a question. I have been working in final cut for a while now and recently jumped over to the canon 5D mark II and 7D. I convert all H.264 to prores LT or HQ and of course when I drag in a clip in converts my timeline automatically for me. The

  • LSMW for MSC1N Transaction to Create Batch

    Hi, I want to create Multiple batches for Large number of Materials. Could any body Please suggest me how to write LSMW for MSC1N. Thanks Bhuvana

  • Help executing MWB generated Procedure

    CREATE OR REPLACE PROCEDURE "SA"."GETBENLIST" ( in_EmployeeID IN NUMBER DEFAULT NULL, RC1 IN OUT Omwb_emulation.globalPkg.RCT1) AS EmployeeID      NUMBER(10,0); StoO_selcnt     INTEGER; StoO_error      INTEGER; StoO_rowcnt     INTEGER; StoO_crowcnt