Classloader isolation and jar manifest Class-Path headers

I have a system where I am loading a set of jars, each with its own URL classloader. So, Jar a is loaded by Loader A, jar b is loaded by Loader B, and so on.
Each jar has a Manifest Class-Path entry declaring its dependence on other jars. So in the example above, a puts c.jar in its Class-path, and, let's say, b also puts c.jar in its Class-path, unbeknownst to a.
Let's say there's a class Foo in c.jar. I want--need--it to be the case that (loader of a.jar == Foo.class.getClassLoader()) from the perspective of classes found in a.jar, and (loader of b.jar == Foo.class.getClassLoader()) from the perspective of classes found in b.jar.
That is, I want a and b to have their own isolated "copies" of c.jar.
Instead, what I'm finding is that Foo.class is loaded once, and his loader "leaks" over to the other jar's loader, if that makes any sense.
Is there any way to accomplish what I am talking about here?
Laird

As I understand the question - no.Hi; I think you misunderstand the question.
The classes are being loaded by the system loader.
Thus there is no way to seperate them.
If you want them seperate then you must use an
explicit class loader to load them.I am using explicit loaders to load them. Let me try again, because I don't think I was clear.
I have an application that has, let's say, nothing at all in its classpath. That is, it was invoked via "java ApplicationMainClass". No classpath.
Now that application reads, let's say, a properties file containing a list of URLs that point to jars.
Now the application creates a new URLClassLoader for each such URL. So if the mythical properties file has ten lines, then I create ten classloaders, each of which points to one and only one URL.
My problem is, even classes loaded by these isolated, separate classloaders are "leaking" across to other loaders. Remember, the parent classloader of all of these classloaders can't see the jars. Its classpath was empty, remember?
The issue is that the findLoadedClass() method of java.lang.ClassLoader scans the whole VM to see if a given Class was loaded before, and if it was, then by default that Class is simply returned. But I don't want that behavior.
Now, I also don't want the behavior of having to load the silly things off disk each and every time. So how do I retain this true multiple classloader isolation?
Thanks,
Laird

Similar Messages

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

  • How do I add the system classpath to Jar Manifest Class-Path

    My application is implemented on win2000 and need to be moved to unix as a executable jar file, the oracle jdbc classes (classes12.zip and classes111.zip) were included in MANIFEST.MF as the following:
    Class-Path: /Oracle/Ora81/jdbc/lib/classes12.zip /Oracle/Ora81/jdbc/lib/classese111.zip
    When I move the jar file to unix, the classpath will be changed, is there a way to make the jar file read the class-path from system CLASSPATH?
    Thank you.
    Y.

    I have the same problem for weeks now, and I can't seem to get it solved. If you found anything please inform me.
    thanks in advance
    Eran

  • J2EE Packaging and manifest Class-Path:

    Does anyone know if Weblogic 6.0 supports the redefined deployment extension mechanism
    that makes use of the 'Class-Path:' entry in the manifest files?
    In our project we have one single .ear file containing a couple of EJB's (.jar
    files) and a Web Application (.war file).
    We are using log4j as logging mechanism and we would like to keep everything in
    the .ear file so that we can make hot-deploys. So we are trying not to make use
    of the classpath in startWebLogic.sh. All of our EJB's and the Web Application
    makes use of log4j.jar. My question is; can I do the following and make it work
    in Weblogic 6.0?
    1. In every EJB .jar file I add the follwing to the manifest file - "Class-Path:
    log4j.jar"
    2. I place the log4j.jar in the root directory of the .ear file.
    By doing this I expect that the ear classloader loads the log4j.jar classes. Am
    I right or do I do something wrong. At least it does not seem to work.
    Using Weblogic 6.0 without service pack.
    Thanks,
    Steen

    This does not work in WebLogic 6.0. It's supposed to be supported in 6.1
    Daniel
    -----Original Message-----
    From: Steen Laursen [mailto:[email protected]]
    Posted At: Wednesday, August 08, 2001 1:32 PM
    Posted To: environment
    Conversation: J2EE Packaging and manifest Class-Path:
    Subject: J2EE Packaging and manifest Class-Path:
    Does anyone know if Weblogic 6.0 supports the redefined
    deployment extension mechanism
    that makes use of the 'Class-Path:' entry in the manifest files?
    In our project we have one single .ear file containing a
    couple of EJB's (.jar
    files) and a Web Application (.war file).
    We are using log4j as logging mechanism and we would like to
    keep everything in
    the .ear file so that we can make hot-deploys. So we are
    trying not to make use
    of the classpath in startWebLogic.sh. All of our EJB's and
    the Web Application
    makes use of log4j.jar. My question is; can I do the
    following and make it work
    in Weblogic 6.0?
    1. In every EJB .jar file I add the follwing to the manifest
    file - "Class-Path:
    log4j.jar"
    2. I place the log4j.jar in the root directory of the .ear file.
    By doing this I expect that the ear classloader loads the
    log4j.jar classes. Am
    I right or do I do something wrong. At least it does not seem
    to work.
    Using Weblogic 6.0 without service pack.
    Thanks,
    Steen

  • Verify a jar's manifest class-path

    I want to verify a jar file's manifest class-path. By that I mean I want to verify that every import of every class in the jar file is reachable on the classpath specified in the jar file's manifest. I tried using a ClassLoader to load every class in the jar file and that does indeed catch a few errors (imported classes that are not on the classpath), but it does not catch them all -- I have situations where loading the class works fine, but when the code is executed, I get NoClassDefFoundError because an imported class is missing from the classpath. I have tried things like calling getDeclaredMethod() on the loaded class to sortof force all the imports to be resolved, but that apparently does not work.
    So, can someone tell me how to sortof "force" a loaded class to reference/validate all its imports?
    Thanks,
    Lee

    Well yes, I know that executing the code would do it. But I'm not in a position to execute the code -- I'm doing this during a build and want to verify that I've built all the jars properly and have all the right classpaths. It's actually quite easy to use ANT to compile and create jar files that produce NoClassDefFoundError at runtime, due to leaving needed classes from the jar, or from bogus classpaths in the jar's manifest.
    So, I was hoping there was some other way to do this. Perhaps I need to do something ugly like examining the bytecodes of each method...
    Thanks,
    Lee

  • Manifest class-path does not works

    Hi,
    We use Jrockit 1.4.2 (latest) on Solaris.
    We found that manifest class-path does not seems to work, we got classdef not found messages.
    If we change the JVM to sun 1.4.2 that everything works perfectly.
    Manifest:
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.5.2
    Created-By: 1.4.1_02-b06 (Sun Microsystems Inc.)
    Implementation-Title: com.clarify.igb.common.ejbserver
    Implementation-Version: 12.5.000
    Implementation-Vendor: Amdocs Inc.
    Specification-Title: ClarifyCRM Business Object Infrastructure
    Specification-Version: 12.5.000
    Specification-Vendor: Amdocs Inc.
    Class-Path: ClfyShared.jar ClfyCbo.jar ClfyClient.jar ClfyWebInf.jar C
    lfyiSupport.jar ClfyUtil.jar jdom.jar ClfyCommon.jar ClfySales.jar Cl
    fymOrder.jar ClfyiAdmin.jar ClfyBilling.jar ClfyBillingManager.jar Cl
    fyEmailProcessor.jar
    What can be the problem?
    Regards.,
    LJ

    Hi Jaejun,
    a.jar should also have a MANIFEST.MF Class-Path refering to b.jar.
    HTH
    Regards,
    Slava Imeshev
    "Jaejun Lee" <[email protected]> wrote in message
    news:3e541ede$[email protected]..
    >
    I meant <CRLF> not <CR> only.
    Thank you.
    "Jaejun Lee" <[email protected]> wrote:
    Ravinder Pal <[email protected]> wrote:
    I have read all message posted in this regard but my problem still
    remain.
    Please read the context to give me some pointers.
    myapp.ear contains
    - myejb.jar contains
    - manifest with Class-Path a.jar b.jar
    - a.jar (Internal)
    - b.jar (Some external Vendor)
    Problem: Call from a.jar classes which reference b.jar classes doesraise
    a ClassNotFoundException.
    Thanks.
    I have a similar problem with WebLogic 7.0 sp1.
    I have to verify this.
    Dose WebLogic support MANIFEST.MF Class-Path in development-mode.
    Indeed, I just put a.jar and b.jar in application directory.
    I put Class-Path: b.jar<carrage-return> in MANIFEST.MF of a.jar.
    But, a.jar cannot find classes in b.jar.
    Do I have to make EAR?

  • Help: manifest class path attribute - OC4J 9.0.3

    I have tried everything I can think of. I have even downloaded the developers version of JRun to ensure my code does deploy under the J2EE spec.
    Per compleating deployment under JRun, I have migrated back to OC4J and made the approperate modifications to orion-web.xml to include the following entry:
    <web-app-class-laoder include-manifest-class-path="true" />
    Even with this entry I get the same class not found statements. I am out of ideas.
    Anyone got some sugestions?
    Info: Ear deployment, static pages deploy under all wars...
    Thanks.
    Andrew
    [email protected]

    I have tried everything I can think of. I have even downloaded the developers version of JRun to ensure my code does deploy under the J2EE spec.
    Per compleating deployment under JRun, I have migrated back to OC4J and made the approperate modifications to orion-web.xml to include the following entry:
    <web-app-class-laoder include-manifest-class-path="true" />
    Even with this entry I get the same class not found statements. I am out of ideas.
    Anyone got some sugestions?
    Info: Ear deployment, static pages deploy under all wars...
    Thanks.
    Andrew
    [email protected]
    Hi Andy -
    Can you check the attribute and make sure it's the following:
    <web web-app-class-loader include-war-manifest-class-path="true"/>
    ^^^
    You have have just typed it in quickly, but I noticed there's a typo in the entry you have above and you are missing the WAR piece of the attribute name.
    There's a how-to document on OTN which has an example of this.
    http://otn.oracle.com/tech/java/oc4j/htdocs/how-to-servlet-warmanifest.html
    cheers
    -steve- Hi Steve
    Where can I find the zip file I went through the link but doesn't have any link to zip file
    Thanks
    Ritesh

  • WAR meta-inf/manifest Class-Path jars use which classloader ?

    If using an expanded EAR structure, my Web App requires some utility classes. I
    can either put these in my :-
    meta-inf/manifest.mf
    Class-Path : utility.jar
    OR
    web-inf/lib
    can contain the utility.jar
    Is there any difference in terms of which classloader is used to load these classes,
    the EAR/EJB classloader or the Web App child classloader ?
    What is recommended ?

    If have found out the answer myself by testing it :-
    A jar in the meta-inf/manifest.mf e.g. Class-Path : utility.jar
    will be loaded by the EAR/EJB level classloader
    whereas
    web-inf/lib containing utility.jar
    will be loaded by the Web App level child classloader.
    Dimitri Rakitine <[email protected]> wrote:
    I have this question too - it appears that 6.1sp2 attempts to use Class-Path
    in jars in WEB-INF/lib - what this Class-Path: is supposed to do ???
    Pete <[email protected]> wrote:
    If using an expanded EAR structure, my Web App requires some utilityclasses. I
    can either put these in my :-
    meta-inf/manifest.mf
    Class-Path : utility.jar
    OR
    web-inf/lib
    can contain the utility.jar
    Is there any difference in terms of which classloader is used to loadthese classes,
    the EAR/EJB classloader or the Web App child classloader ?
    What is recommended ?--
    Dimitri

  • Jar's manifest Class-Path option

    Hey, hopefully this is my last question for a while.
    I downloaded a custom look and feel that's packaged in a jar file.
    Here's the directory structure.
    Main-Program\*.class
    Main-Program\MyProgram.jar (the created jar)
    Main-Program\Data\kunststoff.jar (downloaded look&feel jar)
    I can compile the class files like this:
    javac -classpath .;Data\kunststoff.jar MainClass.java
    and run it like this:
    java.exe -classpath .;Data\kunststoff.jar MainClass
    This works fine. But I want my program to be an executable jar.
    So I create the exec. jar like usual
    jar cf0 MyProgram.jar *.class
    jar umf mainclass.txt MyProgram.jar
    When I package the jar using the manifest file I include the Class-Path var:
    Manifest-Version: 1.0
    Main-Class: Database
    Class-Path: .;Data\kunststoff
    Now when I try to execute the jar it gives me the error:
    "Could not find the main class. Program will exit!"
    Any ideas? thanks.

    Manifest-Version: 1.0
    Main-Class: Database
    Class-Path: .;Data\kunststoff>
    Better change that to "Class-Path: Data/kunststoff.jar"
    (http://java.sun.com/docs/books/tutorial/jar/basics/manifest.html)
    And remember to have a line break after it..
    Now when I try to execute the jar it gives me the
    error:
    "Could not find the main class. Program will exit!">
    But the main class should still be found even if the class-path entry was not totally correct, does Database.class show in jar tf MyProgram.jar?

  • Alternate drives in Jar file Class-Path attribute

    Hello, all. I am working on a project that I would like to package into a single jar file for simple execution. At my place of work classes from EJB are stored on a different drive from where I am doing the development. I am having trouble accessing those classes from the Jars I am creating. When I try the following manifest:
    Main-Class: MyPackage.MyClass
    Class-Path: U:\someFolder
    the application will not start, saying that MyPackage.MyClass cannot be found. This is despite MyPackage.MyClass being properly packaged into the Jar file, as verified by a jar t operation. When I leave off the drive letter in the Class-Path attribute:
    Main-Class: MyPackage.MyClass
    Class-Path: someFolder
    the application starts and executes properly right up until a class from someFolder is needed, at which point exceptions begin to be thrown.
    Any ideas will be much appreciated!
    John Todd

    I was eventually able to find the answer to my own question: Jars do not accept absolute paths at all, only relative paths. Thus, the alternate drive approach will not work. Fortunately I was able to find an alternate solution.
    John Todd

  • Javac / Manifest Class-Path

    Hi guys,
    I have problems with javac not finding classes when I use the extension mechanism.
    I have several jars: abc.jar def.jar ghi.jar ...
    To simplify the classpath when trying to compile another project with these jars, I use the extension mechanism and create a new jar (alphabet.jar) containing only a manifest file:
    Manifest-Version:1.0
    Class-Path: abc.jar def.jar ghi.jar ...The following works fine (assuming for example that abc.jar contains org/alphabet/Abc.class):
    > java -classpath alphabet.jar org.alphabet.AbcBut this fails:
    > javac -classpath alphabet.jar Test.java
    Test.java:1: package org.alphabet does not exist
    import org.alphabet.Abc;
    1 errorTest.java:
    import org.alphabet.Abc;
    public class Test {}I've searched on google and co. for more information but could not get anything. Sun's documentation http://java.sun.com/j2se/1.4/docs/tooldocs/findingclasses.html doesn't mention anything about javac not using the extension mechanism.
    This seems to happen on all JDKs (1.2.2, 1.3.1, 1.4 at least).
    Thanks in advance for your help!

    hi again,
    the next what you should know is that a package has to really exist as directories on your harddisk by compile- and runtime and the name of the class-file needs to be the same name as the class-name in it.
    example:
    c:\javalib\org\alphabet\Abc.java
    c:\javalib\Test.java
    compile both with 1 javac-command
    c:\>cd c:\javalib
    c:\javalib\>javac Test.java
    all imported libs (c:\javalib\org\alphabet\Abc.java) will be automatically compiled with this command. you will have now 2 class-files:
    c:\javalib\org\alphabet\Abc.class
    c:\javalib\Test.class
    now you make a 'manifest'-file for creating a autostartable jar-file:
    create a textfile 'mymanifest.txt' (name is not important) in the root of your projekt with the following content:
    c:\javalib\>mymanifest.txt
    Manifest-Version: 1.0
    Main-Class: Test
    Created-By: Your Name
    (if the start-class is in a package you have to write:
    Main-Class: mypackage.Test)
    now you can make a executable jar (a jar with a manifest) with the command:
    c:\javalib>jar cvfm alphabet.jar mymanifest.txt .
    (dont forget the last point!)
    now you can run the jar simply with:
    (it's now a java-executable)
    c:\javalib>java -jar alphabet.jar
    hope to help
    cu
    oliver scorp
    ps: a jar-file is nothing other than a zip-file, rename it and try it out. you will see that the pathes still exist in the compressed file.
    pps: plz dont forget my dukes!

  • Simple question about environment variables and setting the class path???

    ok I have been trying for a few months now ontrying to set the class path..
    I work with windows vista..
    on the environment variables user variables,
    I have the name of the variable as class
    and the value as C:\Program Files\Java\jdk1.6.0_04\bin;.
    where javac is...
    on the system variables I have
    its name as class
    and the value as C:\Program Files\Java\jdk1.6.0_04\bin;.
    why is this not reading javac

    The PATH environment variable should have as an entry the directory containing your javac executable. The CLASSPATH should have have entries which define your library directories and entries which are your jar file libraries. In the early days, probably the only CLATHPATH entry you will need will be a '.' to indicate the current directory.
    The Java tutorial covers ALL of this.

  • Manifest Class-Path: attribute setting

              Hi there,
              Though the classpath entry is made it is not reacting as expected...Need help
              in understanding the classpath attribute behaviour on web Logic Server 7.0...
              how do I make a jar file inside a war file(war/WEB-INF/lib)refer another jar file
              outside this war.
              

    You looked into the Jar section of the Sun tutorial did you?

  • Class-path manifest attribute

    Hi,
    I have a session bean, that references some external classes. I am deploying the
    application as a ear file. The session beans are stored in a jar file and the
    external classes are stored in a separate jar file. Both the jar files go into
    an ear file. The manifest of the session bean jar file defines the relative URI
    of the other jar file using the Class-path attrtibute. I use JDK 1.3.1. However,
    when I try to deploy the ear, WLS complains about not being able to find the extermal
    class. I use WLS 6.1. This is driving me nuts, any help would be highly appreciated.
    I have attached the EAR file.
    Thanks
    Meeraj

    I was wondering as to why was this constraint placed on EJB's in
    weblogic(that Class-Path can't be used in manifest). After all EJB jar is
    also a jar file, and as what java extensions mechanism dictates, any jar
    file can utilize this feature.
    and how the code would the loadClass/findClass method in the classloader
    look like of I were to disable this feature (like what weblogic currently
    behaves....)
    any thoughts!!!
    - Rajeev Dave
    "Deepak Vohra" <[email protected]> wrote in message
    news:[email protected]...
    Manifest Class-Path
    Use the manifest file to specify that a JAR file can reference another JARfile.
    Standalone EJBs cannot use the Manifest Class-Path. It is only supportedfor
    components that are deployed within an EAR file.
    To use the manifest file to reference another JAR file:
    Specify the name of the referenced JAR file in a Class-Path header in the
    referencing JAR file's Manifest file.
    The referenced JAR file is named using a URL relative to the URL of the
    referencing JAR file.
    Name the manifest file META-INF/MANIFEST.MF in the JAR file
    The Class-Path entry in the Manifest file is as follows:
    Class-Path: AAyy.jar BByy.jar CCyy.jar.
    Meeraj wrote:
    Hi,
    That is not what I want to do. I had got similar stuff working fine with
    JBoss
    by resolving dependencies using Class-path manifest attribute.
    Thanks
    Meeraj
    Deepak Vohra <[email protected]> wrote:
    Add the external classes to the Sessions Bean jar.
    Meeraj Kunnumpurath wrote:
    Hi,
    I have a session bean, that references some external classes. I amdeploying the
    application as a ear file. The session beans are stored in a jar fileand the
    external classes are stored in a separate jar file. Both the jar
    files
    go into
    an ear file. The manifest of the session bean jar file defines therelative URI
    of the other jar file using the Class-path attrtibute. I use JDK
    1.3.1.
    However,
    when I try to deploy the ear, WLS complains about not being able tofind the extermal
    class. I use WLS 6.1. This is driving me nuts, any help would be
    highly
    appreciated.
    I have attached the EAR file.
    Thanks
    Meeraj

  • [svn:fx-trunk] 10055: localized classpath fix for mxmlc.jar,compc. jar and asdoc.jar - add mxmlc_ lang .jar to the path.

    Revision: 10055
    Author:   [email protected]
    Date:     2009-09-08 09:41:10 -0700 (Tue, 08 Sep 2009)
    Log Message:
    localized classpath fix for mxmlc.jar,compc.jar and asdoc.jar - add mxmlc_.jar to the path.  Without these localized errors and warnings aren't generated.
    QE notes: ensure the errors and warnings are generated properly
    Doc notes: no
    Bugs: sdk-22806
    Reviewer:
    Tests run: checkintests:pass
    Is noteworthy for integration: no
    Ticket Links:
        http://bugs.adobe.com/jira/browse/sdk-22806
    Modified Paths:
        flex/sdk/trunk/modules/compiler/build.xml

    So do you know how I can get JavaStudio to add
    library classes and JAR''s into the packaged dist
    file?I was wrong in my previous post. Sorry.
    It's impossible to specify additional classpath with '-jar' option.
    http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/java.html#options
    �-jar
    When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored. �
    So the only solution is to add libs into jar file and declare them in manifest.
    One possible way of how to do it in JSE8 is:
    1. Put all necessary lib jars to some place under src folder.
    2. Add those jars into Compile-time libraries list (Project properties -> Libraries) for correct compilation
    3. Switch to 'Files' JSE8 tab, open manifest.mf file (it's in projects root) and add your lib jars to it.
    Syntax is:
    Class-Path: relative URLs
    That's it.

Maybe you are looking for