0

I am looking to load a library into Java, and then delete the file afterwards- problem is, I can't delete it while it's still in use. Any idea on how to "release" it so that the library will not be in use?

MarkDacek
  • 174
  • 1
  • 10
  • 2
    you want to delete the library contents on the disk or just the library dependency of the project? – SummerCode Dec 22 '14 at 19:49
  • 1
    I don't think you can. **Why** do you want to do this? – Elliott Frisch Dec 22 '14 at 19:52
  • 1
    You should be able to read the file to memory, delete it and then use custom class loader to load classes from in-memory jar. This is a lot of work though. I doubt what you are trying to achieve is worth it. – Piotr Praszmo Dec 22 '14 at 19:55
  • Elliot- Because we don't want the library lying around afterwards Banthar- Anything simpler? – MarkDacek Dec 22 '14 at 20:05
  • 2
    How about [File.deleteOnExit()](http://docs.oracle.com/javase/7/docs/api/java/io/File.html#deleteOnExit())? – Piotr Praszmo Dec 22 '14 at 20:15
  • By library you mean a jar file or a native library (dll)? – Piotr Praszmo Dec 22 '14 at 20:56
  • dll deleteOnExit() hasn't been working – MarkDacek Dec 22 '14 at 21:23
  • possible duplicate of [How to unload dll from java JVM](http://stackoverflow.com/questions/453359/how-to-unload-dll-from-java-jvm) - If that's a DLL, it's even more tricky. Try [this and linked questions](http://stackoverflow.com/questions/453359/how-to-unload-dll-from-java-jvm). – Piotr Praszmo Dec 22 '14 at 21:30

0 Answers0