Loading classes into class path

Hi all,
I have searched this forum but was not able to find an answer to my problem. I know that the class-path header in the manifest file points to classes or jar files on the local file system, but how can I load classes from jar files within my main.jar into the classpath? There is an explanation in the jar tutorial but I don't get it to work.
Stephan

To use a jar file which is in a nother jar file you have to first extract the jar.

Similar Messages

  • Loading class oracle/jpub/runtime/dbws/DbwsProxy into the database

    I am trying to create a Database Web Services call-out in PL/SQL, however, encountered error "ORA-29540: class oracle/jpub/runtime/dbws/DbwsProxy does not exist". I followed some steps to load utl_dbws.jar, utl_dbws_jserver.jar and dbwsclient.jar into the database, but still getting the same error saying DbwsProxy class does not exist. This is very frustrating and I do not know how to fix this. I tried to just load DbwsProxy.class into the database and it executed successfully, however, the database is still complaining that oracle/jpub/runtime/dbws/DbwsProxy does not exist. Does anyone has any idea what's going on? Thanks much. I am cracking my brain out here.

    This is the error message I received when loading:
    The following operations failed
    class java/lang/NumberFormatException: creation (createFailed)
    class java/lang/Number: creation (createFailed)
    class java/lang/Object: creation (createFailed)
    class java/lang/String: creation (createFailed)
    class java/lang/Long: creation (createFailed)
    exiting : Failures occurred during processing
    This is the error message I received in the database after loading dbwsclient.jar:
    ERROR at line 1:
    ORA-29540: class oracle/jpub/runtime/dbws/DbwsProxy does not exist
    ORA-06512: at "SYS.UTL_DBWS", line 135
    ORA-06512: at "SYS.UTL_DBWS", line 132
    ORA-06512: at "MICHELLE.MICH", line 8
    ORA-06512: at line 1
    So that class is still missing. You were suspecting that this class is not loaded successfully into the database? Is it possible for me to just load that particular class into the database?
    Thanks.

  • Getting a number of class path load errors

    Hi, I'm new to jdeveloper and have been perusing the different features and sections of the IDE. When I click on the extensions tab, there are quite a few warnings stating that several class path load entries not found. Is this normal or is there something missing from the IDE?
    Edited by: 936816 on Nov 20, 2012 1:39 PM

    This kind of information probably is not published by the JVM.
    OFC you could rewrite the JVM to support this type of query.
    Maybe something in the jvmstat could help you.

  • JSP Unable to load class

    I am using the core servlets book and Tomcat 3.2.4 to learn JSP. The first example will not work because of the follwing exception:
    org.apache.jasper.compiler.CompileException: E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\jsp\SimpleExample.jsp(14,7) Unable to load class E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\WEB-INF\classes\tags.ExampleTag
    I have the following files in the following paths:
    ExampleTag.java is in the path E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\WEB-INF\classes\tags.ExampleTag and the code is as follows:
    package tags;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import java.io.*;
    /** Very simple JSP tag that just inserts a string
    * ("Custom tag example...") into the output.
    * The actual name of the tag is not defined here;
    * that is given by the Tag Library Descriptor (TLD)
    * file that is referenced by the taglib directive
    * in the JSP file.
    * <P>
    * Taken from Core Servlets and JavaServer Pages
    * from Prentice Hall and Sun Microsystems Press,
    * http://www.coreservlets.com/.
    * &copy; 2000 Marty Hall; may be freely used or adapted.
    public class ExampleTag extends TagSupport {
    public int doStartTag() {
    try {
    JspWriter out = pageContext.getOut();
    out.print("Custom tag example " +
    "(tags.ExampleTag)");
    } catch(IOException ioe) {
    System.out.println("Error in ExampleTag: " + ioe);
    return(SKIP_BODY);
    This is an excert from the Tag Library Descriptor file named csajsp-taglib.tld (the entire file is too long to include). This is in path :E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\jsp
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <!-- a tag library descriptor -->
    <taglib>
    <!-- after this the default space is
    "http://java.sun.com/j2ee/dtds/jsptaglibrary_1_2.dtd"
    -->
    <tlibversion>1.0</tlibversion>
    <jspversion>1.1</jspversion>
    <shortname>csajsp</shortname>
    <!-- ** CHANGED FROM "urn" TO "uri" IN TOMCAT 3.1 ** -->
    <uri></uri>
    <info>
    A tag library from Core Servlets and JavaServer Pages,
    http://www.coreservlets.com/.
    </info>
    <!--
    <tag>
    The name (after prefix) tag will have in JSP code
    <name>example</name>
    The actual class implementing tag. In
    Tomcat 3.1 beta, it MUST be in a package.
    <tagclass>tags.ExampleTag</tagclass>
    Descriptive information about tag.
    <info>Simplest example: inserts one line of output</info>
    One of three values describing what goes between
    start and end tag.
    empty: no body
    JSP: body that is evaluated by container normally,
    then possibly processed by tag
    tagdependent: body is only processed by tag;
    JSP in body is not evaluated.
    ** NOTE: TOMCAT 3.1 FINAL DOES NOT SUPPORT BODYCONTENT **
    ** THE BETA SUPPORTED IT, AND IT IS PART OF SPEC, BUT... **
    <bodycontent>empty</bodycontent>
    </tag>
    -->
    <tag>
    <name>example</name>
    <tagclass>E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\WEB-INF\classes\tags.ExampleTag</tagclass>
    <info>Simplest example: inserts one line of output</info>
    <!-- TOMCAT 3.1 DOES NOT SUPPORT BODYCONTENT
    <bodycontent>empty</bodycontent> -->
    </tag>
    and the .jsp file is SimpleExample.jsp and is located in the path E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\jsp\SimpleExample.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <!--
    Illustration of very simple JSP custom tag.
    Taken from Core Servlets and JavaServer Pages
    from Prentice Hall and Sun Microsystems Press,
    http://www.coreservlets.com/.
    &copy; 2000 Marty Hall; may be freely used or adapted.
    -->
    <HTML>
    <HEAD>
    <%@ taglib uri="csajsp-taglib.tld" prefix="csajsp" %>
    <TITLE><csajsp:example /></TITLE>
    <LINK REL=STYLESHEET
    HREF="JSP-Styles.css"
    TYPE="text/css">
    </HEAD>
    <BODY>
    <H1><csajsp:example /></H1>
    <csajsp:example />
    </BODY>
    </HTML>
    I have tried putting the ExampleTag.java file and the folder that it is in, 'tags', in about every path I can think of and I get the same error. I also tried removing the entire path from the .tld file and just calling for tags.ExampleTag. Still no luck.
    I am using win98.
    Any assistance will be greatly appreciated.
    Thanks,
    Scott

    I compiled the .java and put the .class file in the following path:
    E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\WEB-INF\classes\tags
    I am getting the error: org.apache.jasper.compiler.CompileException: E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\jsp\SimpleExample.jsp(14,7)
    Unable to load class E:\Tomcat324\jakarta-tomcat-3.2.4\webapps\examples\WEB-INF\classes\tags.ExampleTag
    Here is another look at the .java file that I compiled:
    package tags;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import java.io.*;
    /** Very simple JSP tag that just inserts a string
    * ("Custom tag example...") into the output.
    * The actual name of the tag is not defined here;
    * that is given by the Tag Library Descriptor (TLD)
    * file that is referenced by the taglib directive
    * in the JSP file.
    * <P>
    * Taken from Core Servlets and JavaServer Pages
    * from Prentice Hall and Sun Microsystems Press,
    * http://www.coreservlets.com/.
    * � 2000 Marty Hall; may be freely used or adapted.
    public class ExampleTag extends TagSupport {
    public int doStartTag() {
    try {
    JspWriter out = pageContext.getOut();
    out.print("Custom tag example " +
    "(tags.ExampleTag)");
    } catch(IOException ioe) {
    System.out.println("Error in ExampleTag: " + ioe);
    return(SKIP_BODY);
    Any idea why I am still getting an error?

  • Load:Class * not found - in portal

    In the webgui /portal a link is provided.
    when you click the link , which is mapped with the transaction
    code of the ABAP program. gets displayed.
    THis program is used to download PO into the File
    server.
    so File output path is given.
    The user uses F4 help to select the directory / filename as well
    In the bottom we are getting a messge
    load: class FileName not found
    and load: class Directory Select not found
    I use cl_gui_frontend_services=> directory_browse
    and kd_get_filename_on_f4.
    wat might be the problem for this?
    Give me your valuable suggestions
    This is urgent.

    Hi,
    the abap code you use, uses java for getting a filename and for directory browsing. So first of all you have to check,
    if java is activated in your browser. Second, you have to test the frontend services in webgui with transaction se37, ws_query, enter "cd" into field query and executer this. Then you will get a security popup, which you have to accept. If all runs ok,
    you will get the current home directory as result. If you get a java exception again, you have to check the network configuration
    in the java control. It should be the same, as in the browser. If this does not help, try to request the applet ws.jar from the mimerepository .../sap/its/mimes/webgui/2002/applets/ws.jar
    directly. Do you get the security dialog? The error you wrote above means, that the java applet ws.jar could not be loaded.
    Is this an inhouse problem? external or integrated IITS. Which browser, which java version?
    Regards,
    Ralf

  • How to load class from jar file dynamically?

    After I run my Java applicatoin, I need configuring the classpath of jvm to load some classess inside a jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know where the jar file is, what the jar file name is. All depends on the user to tell the jvm the details through some UI. I've tried to write: System.setProperty("java.class.path", "c:\myClass.jar");Class.forName("MyClass"); but failed.
    Can you tell my why and how?
    Thx

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • How  to load  class ???

    please note the below code :
    String systemPath = System.getProperty("java.class.path");
    String classpath = "E:\\Test.jar;" + systemPath;
    System.setProperty("java.class.path",classpath);
    System.out.println("class-path: " + getCompilerClassPath());
    Class.forName("Test");
    Why I can't load the Test class ?? please help me !
    thanks!

    After I run my Java applicatoin, I need configuring
    the classpath of jvm to load some classess inside a
    jar file into the same jvm.How can I achive that?
    I mean, when I run my Java application, I don't know
    where the jar file is, what the jar file name is. All
    depends on the user to tell the jvm the details
    through some UI. I've tried to write:
    System.setProperty("java.class.path",
    "c:\myClass.jar");Class.forName("MyClass"); but
    failed.That won't work. By the time it gets to your code it already has a copy of the original. You can't change it (short of modifying the JVM.)
    Can you tell my why and how?The usual way is to use a custom classloader.
    You can start by looking at java.net.URLClassLoader.

  • Who knows about Jar/Manifest: Class-Path-Attribute

    My question is:
    When packaging my classes and ressource files into a jar file, everything works fine as long as I put the manifest-file into the parent directory of the package folders (there's the main class too) and set its Class-Path-Attribut just as . (a dot).
    I'm working with WinXP Prof.
    As soon as I fill in a path with backslashes or slashes as separator, the produced jar-file doesn't work (class loader does'nt find main-class).
    Is the problem the drive-letter (D:) in the path or do you know something else?
    Greetings
    Frank

    Yes, and likely the . is what you need ...saying: I want the packages which begin in the same directory as the jar running this application. Even if your class is in a package hierarchy like tst.test.Support.class, if the directory tst is in the same directory as the application jar, you would use classpath . not tst/test/Support.class. If you put the tst package in a directory under the folder where the jar resides, say called testit ...you would then have a classpath in the mainifest like testit/. The class path always needs to get you to the root of any package you want to use ...but not into the package itself. Java recognizes when it is looking at a package nesting due to the package declaration syntax in the files, the classpath just points to the location of the root of that package and nothing more. Does this make sense?

  • Classes in class path are trusted?

    The goal I am trying to achieve is to separate classes into two groups (untrusted and trusted) by using different class loaders to load them. All classes that are untrusted will be loaded using a CustomClassLoader. All classes that are trusted are expected to be loaded using the application / system class loader. However, the problem that I seem to be facing is that if a class is in a class path, then it will automatically be loaded by the system class loader, which automatically puts it in the trusted category.
    Suppose on the hard drive is the following:
    c:\asdf\A.class
    c:\asdf\B.class
    Suppose the code for A.class is:
    public class A {
           public void doSomething() {
                    B b = new B();
                    b.doSomething();
    }Suppose the code for B.class is:
    public class B {
            public void doSomething() {
                     File f = new File("c:\\autoexec.bat");
                     f.delete();
    }Also, suppose the classpath consists of the path c:\asdf;
    And suppose there is a custom class loader that accepts a file, and returns a class:
    public class CustomClassLoader extends ClassLoader {
             public Class createClass(File f) {
                       // calls define class
             public Class loadClass(String name, boolean resolveIt) throws ClassNotFoundException {
                      System.out.println("CustomClassLoader.loadClass(" + name + ", " + resolveIt + ")");
                      return super.loadClass(name, resolveIt);
    }Now, suppose the following code:
    CustomClassLoader cc = new CustomClassLoader();
    Class c = cc.createClass(new File("c:\\asdf\\A.class"));
    A a = (A) c.newInstance();
    a.doSomething();The CustomClassLoader is used to load class A. However, since class B is used by class A, and class B is in the class path, the application/system class loader will be used to load class B, unless the CustomClassLoader explicitly loads class B as well.
    But, in the following article: http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html
    the author says the findSystemClass(String name) method must be called, after the local cache has been checked, in order to guarantee the security of the system. Can somebody explain why this is true?
    What I would like to do is to determine if the system class loader has already loaded / defined a class. If not, then I could search the class paths and load that class using the CustomClassLoader. However, there doesn't seem to be a way to check to see if a class has been loaded. There is a findClass(String name) method, but it is protected, so I can't do something like: ClassLoader.getSystemClassLoader().findClass(name).

    java.xxx classes are always loaded by the boot
    classloader.Actually they do not need to be. Your custom classloader can break the classloader delegation chain
    if it wishes in which case the default classloader will not load the java and javax classes. your custom
    loader would then have to load them.
    However this is not advisable as it allows your untrusted code to use its own version of, for example,
    Object. This can cause security problems. It could be possible for the untrusted code to create its
    own version of FileInputStream which does not perform Security checks (and therefore exists outside of
    the sandbox) A great deal of casre needs to be taken if you plan on following this approach.
    In general it is best to put untrusted code into a path that is not in your classpath. Everything works (mostly)
    as you would expect in this case.
    matfud

  • JSP cannot load class from classpath

     

              Ken:
              I run into this problem yesterday too. I'm wondering if you have it resolved? Thank you very much!
              Lucy
              Ken Rimple <[email protected]> wrote:
              >All,
              >
              >I'm using 5.10 WLS, and have a jsp that is trying to access a class in a
              >package loaded in my java classpath. I'm using visual cafe expert
              >edition, and the class is part of the project classpath. To be safe,
              >I've also put it in the sc.ini file under CLASSPATH.
              >
              >The jsp keeps failing with the following error. Servlets I'm using
              >place these things in the HttpSession and are called before this page
              >and they work. I'm baffled, as I even tried the jspc compiler utility
              >adding the classes to the class path.
              >
              >Parsing of JSP File '/ShowResults.jsp' failed:
              >--------------------------------------------------------------------------------
              >
              > /ShowResults.jsp(4): Could not create a bean of type:
              >com.<companyname>.<software>.common.UserSession:
              >java.lang.ClassNotFoundException: class
              >com.<companyname>.<software>.common.UserSession :
              >java.lang.InstantiationException:
              >com/<companyname>/<software>/common/UserSession
              >probably occurred due to an error in /ShowResults.jsp line 4:
              ><jsp:useBean id="user_session" scope="session"
              >class="com.<companyname>.<software>.common.UserSession" />
              >--------------------------------------------------------------------------------
              >
              >(<companyname> and <software> are regular names. The file is in the
              >class path and is used by Servlets.
              >
              >It's almost as if the jsp compiler is ignoring any class paths.
              >
              >Please help if anyone has made this work. I'm stuck.
              >
              >Ken Rimple
              >
              >
              

  • Dont want to hard code the -Djava.class.path...notation question

    Hello everyone,
    I have a c++ program that is compiled into a DLL file. It calls the JNI_CreateJavaVM. I have the whole thing working but now I need to port it and the jar file to another machine.
    right now i am setting the options this way:
    #define USER_CLASSPATH "c:\\javaClasses\\intec.jar.zip" /* where PRLocalBridge.class is */
    #define PRCLASS "com/intec/intecapi/PRLocalBridge"
    bool PRLocalBridgeMain(){
         JavaVMOption options[1];
         options[0].optionString = "-Djava.class.path=" USER_CLASSPATH;
         vm_args.version = JNI_VERSION_1_4;//0x00010002;
         vm_args.options = options;
         vm_args.nOptions = 0;
         vm_args.ignoreUnrecognized = JNI_TRUE;
        /* Create the Java VM */
        res = JNI_CreateJavaVM(&jvm, (void**)&env,&vm_args);
        if (res < 0) {
         return (bool*)errorHandler('b', CANT_INVOKE_JVM);
        cls = env->FindClass(PRCLASS);
    }where USER_CLASSPATH is hardcoded directly to where the jar
    file is located. in other machines, it may not be loaded
    in that file structure. how do i softcode the path?
    ive put the jar in my classpath but that doesnt seem to work
    (unless i didnt have USER_CLASSPATH set properly). Thanks
    in advance :)
    txjump

    hi bschauwe,
    thanks for the suggestions! i was hoping you would reply. You have helped some others with classpath questions. :)
    since its a dll, can you pass it values?
    we do have an ini file that is already created but the file parser is in java so i would have to write another one in c. id like to stay away from that though. cause if it gets messed up or goes missing, clients wont be able to reach the java program, and in turn the database.
    the classpath environment variable sounds like a good idea...will check into that. eventually we plan to wrap our software up in installshield so that would really be nice. clients could be ignorant of environment variables and still be able to run everything.
    my solution for now has been to find my jar file by recursively searching the c drive. and use GetFilePath() to get the full path and pass that to JNI_CreateJavaVM. i did get it to work...just wondering if this is a good idea.
    i was thinking that if the dll is in the same folder as the jar file i could just use dot notation but that just doesnt seem like a good idea to make that assumption. but i think java does something similar 'cause Sun says not to move the java.dll file.
    thanks for your input,
    txjump

  • Class path issue

    my jar class path is defined in the metainf file.
    after the installation my jar is placed in the folder:
    client/lib/company libs
    and the run time location is from:
    client/bin
    I need to load a configuration file located in:
    client/conf/file.properties
    I added the path ../conf to the class path and i got an exception when i try to load the file.
    I thought of locating the file according to the jar location and added the path: ../../conf
    to the class oath but still....
    does anyone have an idea why cant i load the file?
    thanks,
    Liat

    If you look in the JavaDoc API under Class the method getResource() shows:
    Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the * defining class loader of the class.
    This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResource.
    What this is saying is that it delegates to the call to the classloader, so its the same as saying getClass().getClassLoader().getResource(). The difference is, this method will append the package name of the class you are calling it from if you do NOT have a '/' character as the first character of the string. Your example shows you do NOT have a '/' character at the start. So whatever package name you have for the class that the code snippet is found in, that package name is being prepended to the string AND the '.' are turned into '/' characters.
    In your example, make sure that you use a / at the start. Remember that it first asks the parent loader to find the resource, if that fails, it tries the classpath of the JVM, and finally if that fails, it uses the classpath of the classloader of the class where the call is made. If you use "/conf/maestro-default-user-config.properties", then it will be looking for this file relative to your applications startup root path.

  • Load:Class filename not found portal

    In the webgui /portal a link is provided.
    when you click the link , which is mapped with the transaction
    code of the ABAP program. gets displayed.
    THis program is used to download PO into the File
    server.
    so File output path is given.
    The user uses F4 help to select the directory / filename as well
    In the bottom we are getting a messge
    load: class FileName not found
    and load: class Directory Select not found
    I use cl_gui_frontend_services=> directory_browse
    and kd_get_filename_on_f4.
    wat might be the problem for this?
    Give me your valuable suggestions
    This is urgent.

    Hello,
    Can you tell us if you resolve your issue and how?
    Thanks

  • Lost on the Class Path

    I'm having some serious trouble with class package path issues ... ugh!
    I've downloaded a fairly complex and well programmed FLA file and other source files in AS 3.0, and just started to adapt it for a custom application.  When I published the FLA and packages in FLash CS3, everything worked perfectly.  Then I just got Flash CS4 a few days ago, and so opened the same application in CS4, and also published it fine.  Yet, once I started to make some very simple customizations, such as create a new MovieClip, and then added "linkage" to the MovieClip in the library, the trouble started. Getting the new external class to associate to the new MovieClip was not working (although it was in the same location as the other package file, with the same class package designation), so of course I went to take a look at the preferences and set the general class path.  Interestingly, the class path was completely blank (I just installed CS4 that day).  Yet then, why was the application still working initially with no class path set?  All of your original classes were loading fine, and the application was working.  So, then when I went into actually set a class path (my new class is in the same folder: .../com/parkerandkent/components/classic/photogallery ), I start getting all kinds of errors ... and now, even if I revert back to having no class path at all, the application does not work at all (when it originally did with no class path at all).  Strange!  I am very confused about what is going on.
    There are 5 primary .as package files, all of which are linked to MovieClips in the Library:
    ClassicPhotoGallery.as
    Photo.as
    Thumb.as
    Thumbs.as
    CallTag.as (the new class)
    I've checked the properties linkage for each of these, and they all appear correct also.
    Currently, I have all of these class paths set:
       - "/Users/mac/_EXTRA/ArtMuse/GALLERY"
       - " "/Users/mac/_EXTRA/ArtMuse/GALLERY/com/parkerandkent/components/classic/photogallery"
    Currently, I get these these error messages, which are referring to only 3 of 5 total .as files (which are all in the same location, and all have the same class path designation - and none of these files is the new class I made, which now appears to be referenced okay).
    Photo.as Line 1:
    5001: The name of package 'com.parkerandkent.components.classic.photogallery' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. /Users/mac/_EXTRA/ArtMuse/GALLERY/com/parkerandkent/components/classic/photogallery/Photo .as
    Thumb.as Line 1:
    5001: The name of package 'com.parkerandkent.components.classic.photogallery' does not reflect the location of this file. Please change the package definition's name inside this file, or move the file. /Users/mac/_EXTRA/ArtMuse/GALLERY/com/parkerandkent/components/classic/photogallery/Thumb .as

    Again, the class path package designation is the same for all 5 .as files:
    package com.parkerandkent.components.classic.photogallery {
    yet the application is not working, and I get only those errors posted above.
    If I remove all source path designations, then I get NO error messages, and yet the application does not work (although, I swear it was working this way originally).

  • URLClassLoader loading class from jarB, which uses classes from jarC

    Hi, here's my problem:
    I have a classA in executable jarA.
    This uses URLClassLoader to load classB from jarB. So far so good.
    But classB uses classC, which lives in jarC. jarC is specified in the Class-Path of the manifest in jarB. But classB gets a ClassNotFound exception when it tries to use classC.
    The situation I want to achieve looks like this (sorry for the bad art; it's almost impossible to make it look better because sun strips out extra spaces):
    jarA:
    classA-----> URLClassLoader(jarB).loadClass(classB)
    jarB:
    Class-Path jarC
    classB------> new classC
    jarC:
    classC
    My expectation was that URLClassLoader would automatically be used to load all the classes that classB uses, and that it would extend its classpath by the classpath specified in the manifest of jarB, just like the default classloader does. Anyone know what I'm doing wrong?
    When I do the following, i.e. use only the default classloader, everything works fine. Unfortunately I won't know where jarB is until runtime, so I can't actually do this:
    jarA:
    Class-Path jarC
    classA-----> new classB
    jarB:
    Class-Path jarC
    classB------> new classC
    jarC:
    classC
    thanks alot
    j

    Actually, there is definitely a way to make this work. A plugin engine has to handle this in order for plugins loaded by separate loaders to be able to share class instances with one another (dependency). My engine does static runtime plugin dependency resolution, which means it parsers every plugin's config file, then after all plugins are in the "registry" it goes back and resolves all dependencies. How it does this is that each PluginClassLoader keeps a list of "dependent" classloaders. So, if the engine finds plugin A, B, and C, and B depends on C (declares this in its config file), the engine creates 3 class loaders (custom loader called PluginClassLoader), one for each plugin. This is done so that the plugin can be unloaded or reloaded at runtime without having to shut the application down. Now, since B depends on C, when plugin B code requests a class found in C, the JVM first asks B's loader to find the class. The "normal" delegation model of Java is for B's loader to first look in the parent hierarchy, then in its own classpath. The problem with this approach is that in order to support reloadable and unloadable plugins, you do NOT want your plugin .jar file at any location within the main application classpath. The plugin .jar file should be able to be at any URL location outside of any other classpath, even perhaps at another web site.
    So, the JVM asks B to find the class in C. But B's loader isn't able to find it because it is not in B's classpath. The trick is to do one of a couple things. First, remember that each loader keeps a list of dependent loaders. Second, in order to avoid any tie-in to the main classpath, we break the normal classloader delegation model by overriding the loadClass() method. In here we want to first check our local cache of loaded classes. The built-in method findLoadedClass() handles this for us. If that doesn't return a Class, then we want to look in our own classpath. In this case, we only want to look for any classes in B's plugin .jar file. C's class of course wont be found here. So the next step is to delegate to our "dependent" list of loaders. Aha, you say? This is the trick (credit goes to the Eclipse IDE team where a few members taught me this and was able to help me solve my very same problem). By delegating to a dependent loader, B's loader effectively asks C's loader to find C's class. The same thing happens, only this time it is now C's loader doing the work. The very first time the calls is made, no classes are loaded yet, so the finding of the C class in the local cache of C's loader wont yet work. The next step though, looking in C's classpath (C's .jar file) WILL find the class. It is loaded, put in C's loader cache and the Class is returned. Now, at this point B now has a Class from C's classpath that it can use.
    Now, my first foray into this made me think that if B asks C to find it, and C finds it and loads the bytecode, doesn't B's loader also need the bytecode in order to properly "see" the C class. Apparently, this is not needed. I am guessing the JVM keeps a repository of bytecode, so that so long as you have the C ref (location in the JVM's memory where C's bytecode is), you don't need to re-load the bytecode of C into B's loader. Thus, B's loader now can "see" the C class without actually having to have loaded the bytecode of C. Now, B's code can typecast C, use it, etc. Beautiful aint it?
    Let me know if you have any further questions.

Maybe you are looking for

  • How do I verify my laptop to use the same Apple ID that I use on my iPod in order to update an application?

    I'm trying to update an application on my laptop that I have also downloaded on my iPod, but for some reason every time I try to sign in to update, it claims my device has not been verified. Any ideas on what I could do?

  • HT4362 Photo sharing

    I want to set up photo sharing with my Apple TV.  When I go to Advanced in iTunes I find sharing options, but iTunes will not let me choose "Selected albums, events, faces"  That option is gray.  All I can choose is "All photos......"  What am I doin

  • A pool operation was specified for a pooled resource that does not belong t

    hi i left the server running for days so my application was running i refresh the page by clicking the ok button in small popup box,the page was refresh but when i what to select my lov am geting this error A pool operation was specified for a pooled

  • Need a fix for the 'folder last opened date'

    I have been using Hazel [from www.noodlesoft.com] to set the colours of recently opened or modified files to make them easier to spot. Within Hazel, I have set rules to monitor files contained in a named folder (and sub-folders contained therein) so

  • Coffee spill and power book

    could you please advise where to go to clean my powerbook after coffee spill on the keyboard, in sf bay area. do apple stores offer this kind of service, please?