Class.forname()

P

Phoneix

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
 
M

Matt Humphrey

Phoneix said:
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 (e-mail address removed) http://www.iviz.com/
 
P

Phoneix

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 (e-mail address removed) 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 :)
 
B

Babu Kalakrishnan

Phoneix said:
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
 
L

Lee Fesperman

Phoneix said:
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.
 
P

Phoneix

Babu Kalakrishnan said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top