Class.forname()

Discussion in 'Java' started by Phoneix, Aug 11, 2004.

  1. Phoneix

    Phoneix Guest

    Hello ,
    I have a necessity to delete a jar file which is in the CLASSPATH.
    But JVM locks it after a class.forName() call, even though the class
    loaded is NOT in the JAR file I want to delete. ( I cannot remove the
    JAR file from the CLASSPATH )

    First of all is it possible?

    Any help is appreciated

    thanks in advance
     
    Phoneix, Aug 11, 2004
    #1
    1. Advertising

  2. "Phoneix" <> wrote in message
    news:...
    > Hello ,
    > I have a necessity to delete a jar file which is in the CLASSPATH.
    > But JVM locks it after a class.forName() call, even though the class
    > loaded is NOT in the JAR file I want to delete. ( I cannot remove the
    > JAR file from the CLASSPATH )
    >
    > First of all is it possible?


    I would guess that what's really happening is that the Class.forName ()
    opens the jars in the classpath and keeps them open for future queries.
    They should be released when the application halts. Can you describe what
    you're really trying to accomplish and why you need to modify the jars of a
    program that is running?

    Cheers,
    Matt Humphrey http://www.iviz.com/
     
    Matt Humphrey, Aug 12, 2004
    #2
    1. Advertising

  3. Phoneix

    Phoneix Guest

    >
    > I would guess that what's really happening is that the Class.forName ()
    > opens the jars in the classpath and keeps them open for future queries.
    > They should be released when the application halts. Can you describe what
    > you're really trying to accomplish and why you need to modify the jars of a
    > program that is running?
    >
    > Cheers,
    > Matt Humphrey http://www.iviz.com/


    thanks for the reply Matt.
    Yes, We have an application which acts as a launcher for many other
    applications. One of the applications which gets launched is an Value
    Objects generation tool which regenerates the jar file if the customer
    makes changes to the value objects. Trouble is this jar is in the
    class path of the launcher which is required for other tools.
    To complicate matters we are not using Class.forname() actually. We
    are using JNI's equivalent of jinenv->findClass() . ( since our apps
    has both C++ and Java parts ) Complicated enough ? :) . WE donot
    know how to close the file handles for the JAR files opened during the
    findclass() search by the systemClassLoader. We though of writing a
    custom class loader but how to we hook up that to "jvm.dll" which is
    what we load from our C++ program.( And then do a create_JVM call etc
    ).
    Every text talks about how there 3 classloaders gets into action or
    what is heirarchy of search etc but no one talks how to release the
    handles opened during a search for class. Funny thing is even if you
    do a resolve or find for a non-existent class name , JVM locks the JAR
    files . I tried forcing GC hoping since there is no reference anywhere
    to the class and the lock will be released , nope the file locks are
    firm as ever .
    Coming from a assembly/C++ background these lack of control is
    frustrating :)
     
    Phoneix, Aug 12, 2004
    #3
  4. Phoneix wrote:
    > Hello ,
    > I have a necessity to delete a jar file which is in the CLASSPATH.
    > But JVM locks it after a class.forName() call, even though the class
    > loaded is NOT in the JAR file I want to delete. ( I cannot remove the
    > JAR file from the CLASSPATH )
    >
    > First of all is it possible?
    >


    I think this is because of the aggressive caching strategy adopted by the
    classes in the java.util.jar (and java.util.zip) package. And the caching
    code is in the native part of the library - so you can't even create a
    custom classloader by simply extending the jar classes - you probably
    have to rewrite the ZIP classes :-(

    There are several side effects of this if you're trying to use the zip/jar
    library code even in applications other than classloading. For example, if you
    open a ZIP file, add some more files to it, *and close it*, reopening it a
    second time will not even show the new entries !! (Even though the zip file does
    have the new data in it) - There were several open bug reports about this at
    Sun. (Haven't checked if this is fixed in the 1.5 betas)

    BK
     
    Babu Kalakrishnan, Aug 12, 2004
    #4
  5. Phoneix wrote:
    >
    > Yes, We have an application which acts as a launcher for many other
    > applications. One of the applications which gets launched is an Value
    > Objects generation tool which regenerates the jar file if the customer
    > makes changes to the value objects. Trouble is this jar is in the
    > class path of the launcher which is required for other tools.
    > To complicate matters we are not using Class.forname() actually. We
    > are using JNI's equivalent of jinenv->findClass() . ( since our apps
    > has both C++ and Java parts ) Complicated enough ? :) . WE donot
    > know how to close the file handles for the JAR files opened during the
    > findclass() search by the systemClassLoader. We though of writing a
    > custom class loader but how to we hook up that to "jvm.dll" which is
    > what we load from our C++ program.( And then do a create_JVM call etc
    > ).
    > Every text talks about how there 3 classloaders gets into action or
    > what is heirarchy of search etc but no one talks how to release the
    > handles opened during a search for class. Funny thing is even if you
    > do a resolve or find for a non-existent class name , JVM locks the JAR
    > files . I tried forcing GC hoping since there is no reference anywhere
    > to the class and the lock will be released , nope the file locks are
    > firm as ever .


    I really doubt that you are going to be able to get the system classloader to loosen its
    grip on jar files in the classpath. You're going to have to write your own classloader.
    Give the system classloader a 'rump' classpath (that includes your classloader) without
    those jar files. Your classloader can then provide the capability to release jar files
    under its control. Your JNI won't be able to load things directly. It will need to go
    through a Java wrapper (also on the rump classpath) to do the loading with your custom
    classloader.

    --
    Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
    ==============================================================
    * The Ultimate DBMS is here!
    * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
     
    Lee Fesperman, Aug 12, 2004
    #5
  6. Phoneix

    Phoneix Guest

    Babu Kalakrishnan <> wrote in message news:<>...
    > Phoneix wrote:
    > > Hello ,
    > > I have a necessity to delete a jar file which is in the CLASSPATH.
    > > But JVM locks it after a class.forName() call, even though the class
    > > loaded is NOT in the JAR file I want to delete. ( I cannot remove the
    > > JAR file from the CLASSPATH )
    > >
    > > First of all is it possible?
    > >

    >
    > I think this is because of the aggressive caching strategy adopted by the
    > classes in the java.util.jar (and java.util.zip) package. And the caching
    > code is in the native part of the library - so you can't even create a
    > custom classloader by simply extending the jar classes - you probably
    > have to rewrite the ZIP classes :-(
    >
    >


    thanks for the reply Babu ,
    just curious, how do look at the source , decompiler or is the source
    available somewhere ? thanks
     
    Phoneix, Aug 13, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iksrazal

    Re: Class.forname() vs clone()

    iksrazal, Jun 27, 2003, in forum: Java
    Replies:
    0
    Views:
    1,608
    iksrazal
    Jun 27, 2003
  2. Ahmed Moustafa

    performance of Class.forname()?

    Ahmed Moustafa, Jul 20, 2003, in forum: Java
    Replies:
    14
    Views:
    5,960
    Chris Smith
    Jul 29, 2003
  3. H.MuthuKumaraRajan

    .class and Class.forName

    H.MuthuKumaraRajan, Nov 6, 2003, in forum: Java
    Replies:
    11
    Views:
    1,746
    H.MuthuKumaraRajan
    Nov 7, 2003
  4. cyril
    Replies:
    2
    Views:
    3,878
    cyril
    Aug 25, 2004
  5. Madni
    Replies:
    1
    Views:
    5,895
Loading...

Share This Page