Classloader won't let me delete jar file!

Hi-
I am writing a classloader that runs main from a class called MyMain. MyMain loads classes from a jar file called MattTable.jar. I need to be able to delete the jar file once the classes are loaded from it, or even just delete it at the end of the program. Either way, the classloader will not release it so I cannot delete the jar file until after my program finishes. I want to be able to delete it from with in my code after the method is invoked.
URL urls[] = new URL[] { new File(".").toURL() };
URLClassLoader loader = new URLClassLoader( urls );
Class c = loader.loadClass(mainClass);
Method m1 = c.getMethod("main", new Class[] { args.getClass() });
//main loads classes from an outside jar file
m1.invoke( null, new Object[] {args} );
//Here is where I want to delete the jar file
//I would even accept file.deleteOnExit() but this won't work either
If anyone can help me figure out how to delete this file, it would be a great help!
Thanks,
Matt

Hi,
I've created a small classloader for jar files which releases the handle every time a class is loaded. It might still need some optimization, but at least it works:import java.util.zip.*;
import java.util.*;
import java.io.*;
public class ZipClassLoader extends ClassLoader {
     private Hashtable classes = new Hashtable();
     private File f;
     public ZipClassLoader(String zipFileName) {
          this (new File(zipFileName));
     public ZipClassLoader(File zipFile) {
          f = zipFile;
     public Class loadClass(String className) throws ClassNotFoundException {
          return (loadClass(className, true));
     public synchronized Class loadClass(String className, boolean resolve) throws ClassNotFoundException {
          if (classes.containsKey(className)) return (Class)classes.get(className);
          ZipFile zipFile = null;
          BufferedInputStream bis = null;
          byte[] res = null;
          try {
               zipFile = new ZipFile(f);
               ZipEntry zipEntry = zipFile.getEntry(className.replace('.', '/')+".class");
               res = new byte[(int)zipEntry.getSize()];
               bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
               bis.read(res, 0, res.length);
          } catch (Exception ex) {
          } finally {
               if (bis!=null) {
                    try {
                         bis.close();
                    } catch (IOException ioex) {}
               if (zipFile!=null) {
                    try {
                         zipFile.close();
                    } catch (IOException ioex) {}
          if (res == null) return super.findSystemClass(className);
          Class clazz = defineClass(className, res, 0, res.length);
          if (clazz == null) throw new ClassFormatError();
          if (resolve) resolveClass(clazz);
          classes.put(className, clazz);
          return(clazz);
}This is the test program I've created. It loads a class from the Apache log4j jar file, and deletes the file when the class is loaded:import java.io.File;
public class Test {
     public static void main(String[] args) throws Exception {
          File f = new File("C:\\jartest\\log4j-1.2.6.jar");
          ZipClassLoader zl = new ZipClassLoader (f);
          Class c = zl.loadClass ("org.apache.log4j.ConsoleAppender", true);
          Object o = c.newInstance();
          System.out.println (o.getClass().getName());
          f.delete();
}

Similar Messages

  • My Iomega External Hard drive won't let me delete/copy files...

    I haven't used my external hard drive since buying my Macbook Pro.
    I have just tried to delete some files from it and then copy some Uni work from my Documents onto my hard drive.. but it won't work.
    Is there anything I need to download?

    Install software such as the NTFS-3G drivers.
    (61239)

  • TS2942 I want to delete a file off a thumb drive but get error 1407 which won't let me delete or trash the file.  What do I do?

    I want to delete a file off a thumb drive but get error 1407 which won't let me delete or trash the file.  What do I do?

    Hmmm, what Format is the Thumb drive?
    In the Mac/AFP world...
      errFSNotAFolder               = -1407, /* Expected a folder, got a file */
    Is there perhaps a colon or Backslash, or slash in the filename?

  • Why won't preview let me delete all files (instead of all but one)

    In all OSX versions up to snow leopard in preview there was the option to select all open items and move the files to the trash. For some reason unknown to me, in 10.8.5 mountain lion that option no longer exists. Now preview lets me delete all files except one. If you have 2 images open you can move 1 to the trash. If you have 99 open you can move 98 to trash and if you have 1 open, you cannot move it to trash. Is there some code available where I can undo this restriction?

    Do you also have them on another computer, iPad or iPhone,  IF you do then it may be syncing them back

  • I want to delete ConstaSurf and SearchProtect but I get a message that they are in use and it won't let me delete them.

    I started to download Firefox and without realizing it I agreed to some additional programs that I do not want on my computer. The ones I can identify are ConstaSurf and SearchProtect. When I try to delete them, I get a notification that they are in use or in another file, and it won't let me delete them. I would like to delete them and then try downloading Firefox more carefully. Thanks for any help. I am not computer savvy.

    See this: http://malwaretips.com/blogs/constasurf-virus-removal/
    For step 1 - Uninstall ConstaSurf program from your computer - thru the Control Panel
    If that's where you get that message about them bring in use, try closing Firefox and any other browsers that you may have open and then try to uninstall those two.

  • ICal keeps sending alarms for past events and won't let me delete items from calendar, I hit delete but the event just keeps multiplying on my calendar?

    iCal just started repeatedly sending me alarms a couple of days ago. I thought deleting the event from my calendar would help but it won't let me delete them, they just keep multiplying in my calendar. Help please

    Hello again,
    Well I seem to have overcome the problem, but not easily, and not by identifying the cause. I don't like that I don't know what caused the trouble. I make no guarantees, but this is what I did (on an iMac with Snow Leopard 10.6.8). Be sure to create backup copies of your files first:
    [Note: before you do any of this, you may want to try running Disk Utility program (found in Applications/Utilities/) and run the "Repair Permissions" option. See if that solves anything, but it didn't for me]
    a) I exported my iCal as an archive: Menu item, "File/Export/iCal Archive...". This won't likely do you any good, though, as something was wrong with it and I could not re-import it. But try anyhow.
    b) After backing them up, I deleted the folders and contents inside the Calendars folder: "Users/<your user name>/Library/Calendars/<subdirectories>". To create a backup, right-click on the Calendar folder and choose "compress Calendars" from the pop-up menu. Then drag the folder contents into the trash.
    c) After creating backup copies, delete (drag into the trash) these preferences files found in "Users/<your username>/Library/Preferences" (the slashes delimit the folder names):
      Users/<your username>/Library/Preferences/com.apple.iCal.plist
      Users/<your username>/Library/Preferences/com.apple.iCal.helper.plist
      Users/<your username>/Library/Preferences/ByHost/com.apple.iCal.helper.<some convoluted hex number>.plist
    d) Restart your computer;
    e) Launch iCal and reimport the individual calendar files you exported earlier.
    Hopefully all is well.
    Let me emphasize again that you will not likely succeed in reimporting the calendar archive. In the first place it likely contains corrupted data that caused your trouble in the first place. So you will need to import the individual calendars that have been exported. Be very certain to export these individually first.
    And if you want to make doubly certain, then copy and paste some of your important and key events into a TextEdit file and save that file in case you don't succeed.
    Perhaps you subscribed to some online calendar? If I recall correctly I had imported a calendar when the World Cup Soccer series was happening; I speculate that might have contributed to the issue. I wish I could have found exactly what caused the trouble. It may have been some older, less compatible format that was retained through a series of Mac OS updates.
    Good luck.

  • I bought a song on iTunes...but it must not have downloaded all the way an now I can't get it to play and it won't let me delete it...I also can't purchase it again cause it says I done bought it...any suggestions?

    I bought a song on iTunes...but it must not have downloaded all the way an now I can't get it to play and it won't let me delete it...I also can't purchase it again cause it says I done bought it...any suggestions?

    Try this:
    http://support.apple.com/kb/HT2519

  • I was on Instagram and I clicked this link that lead me to safari but a box keeps popping up and it won't let me Delete the tab, can someone help me pleased??? I can't even use safari, is there a way to delete it or something???

    I Was on Instagram and I clicked a link that lead me to safari and when I got there a box kept coming up and saying a b c d e f g.... And so on. It won't let me delete the tab and I can't even use safari, can someone please help!!!!!??????

    Quit Safari completely, clear Safari and reboot the iPad.
    Go to the home screen first by tapping the home button. Double tap the home button and the recents tray will appear with all of your recent apps displayed at the bottom. Tap and hold down on any app icon until it begins to wiggle. Tap the minus sign in the upper left corner of the Safari app icon. Tap the home button or anywhere above the task bar.
    Go to Settings>Safari>Clear History, Cookies and Data.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up

  • I've recently changed the email address on my i tunes account. The emai address on my icloud account hasn't changed, so i can't buy additional storage. It also won't let me delete my existing icloud acc.

    I've recently changed the email address on my i tunes account. The emai address on my icloud account hasn't changed, so i can't buy additional storage. It also won't let me delete my existing icloud acc.

    To change the iCloud ID on your phone, first save your photo stream photos to your camera roll (if not already there) by opening the my photo stream album, tapping Edit, tap the photo thumbnails, tap Share, tap Save to Camera Roll.  Then go to Settings>iCloud, tap Delete Account, then sign back in with the changed ID.  This deletes the account and your iCloud data from your phone, but not from iCloud.  Provided you are signing back into the same account, your iCloud data will reappear on your phone when you sign back in.

  • How can I add .m4r files (thatI have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes ans it won't let me drag the files to the sidebar...

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

  • JRockIt Deleting JAR files - Error loading class

    Hi there,
    Customer is facing a very weird issue. Their application has an application that contains some EJBs and Web applications that, apparently for no reason, it starts to unload classes and delete JAR files and WAR files from the Weblogic's "extract" directory. If I bounce the application, everything starts working fine until a moment where the issues starts again.
    I thought this was any kind of memory issue that was not allowing the JVM to free enough resource for loading the classes again after unloading it. But we gave enough memory for the JVM and it stills happening.
    Thoughts? Any idea that might help us on troubleshooting is very welcome at this time.
    Thanks in advance,
    Davi

    e-blade wrote:
    Manifest-Version: 1.0
    Class-Path: lib/tools.jar
    Created-By: 1.6.0_18 (Sun Microsystems Inc.)
    Main-Class: MainThe line in bold means: when app.jar will be run, it will look for additional classes in <same OS directory as itself>/lib/tools.jar.
    It does not mean that it will look inside itself in the JAR directory /lib/tools.jar.

  • ITunes Shopping Cart won't let me delete items.

    I have some items in my shopping cart that I need to delete because I've already purchased them. But the problem is that it won't let me delete them and it also says that it is not available in the Canadian Store. If someone knows how to fix this that would be great.

    Same problem as well with music videos I added that were originally single purchase items and then the next day became Album Only in my shopping cart (though they really weren't) and now I can't delete them. I've tried several tricks to no avail.
    I've called Apple Care twice with no resolution. They keep wanting to send me to iTunes Store support but I don't think the people answering there even know how to use a computer. They refuse to "escalate" the issue even though no one has still provided an answer. All I want is for the iTunes staff to delete my entire shopping cart contents but no.
    Obvious something is seriously messed-up with the iTMS database and Apple is covering it up to prevent a huge blow to their Christmas sales. I'm sure the DBAs are working round the clock to fix this with no resolution yet.
    In 25 years this is the worst support I've ever had from Apple.

  • How do I keep my email password from remaining in Preferences? I want to enter it every time I get my mail. I upgraded to OS M Lion but it won't let me delete it from preferences. It's worked prior to using M. Lion. Any suggestions? Thanks!! Jen

    How do I keep my email password from remaining in Preferences? I want to enter it every time I get my mail. I upgraded to OS M Lion but it won't let me delete it from preferences (the password from Account Info). Once you enter the password, it keeps it permanently. i do not want that.  It's worked prior to using M. Lion. Any suggestions? Also, The other pressing issue i have is, I DO NOT want ANY mail showing in my inboxes when Mail starts UNTIL i enter that password for each account. Instead of creating different user accounts for the MacBook, it's just easier this way. Or is it? If this is a permanent thing, then I may switch back to Lion. I guess I shoud've waited until the kinks were out before installing (**** Mac-head!)
    Thank you all kindly for any suggestions & your time
    Regards,
    JC

    I DO NOT want ANY mail showing in my inboxes when Mail starts UNTIL i enter that password for each account.
    That is simply not possible with Mail, and never has been.  Anyone who uses your account can see all messages stored in Mail.  The only true solution is to not let other people use your account.  Let other people use the guest account, or if you share the machine with someone else, set up a separate user account for that person.  This will also solve the problem of remembering the password.  It will become a non-issue for Mail to remember your password if nobody else has access to your account.

  • How do you change the artwork in the new itunes? it won't let me delete it

    how do you change the album artwork in the new iTunes? it won't let me delete the old artwork even when I highlight it

    The new iTunes 12 Get Info dialog lacks right-click context menus (at least for now) but it still accepts most standard keyboard shortcuts and drag & drop actions.
    Delete Artwork
    On the artwork tab of Get Into, tap the image in question, use Backspace or Ctrl+X. Delete doesn't work.
    Or, tap the image at the top left of Get Info, this time use Backspace or Delete, it is Ctrl+X that doesn't work.
    Add Artwork
    Select artwork, press Ctrl+C to copy, tap the centre of the Artwork tab, press Ctrl+V to paste.
    Or, select artwork, press Ctrl+C to copy, tap the small image area at the top left, press Ctrl+V to paste.
    Or, you can drag & drop to, or sometimes from, the same locations.
    You can also copy artwork from the Get Info dialog to Windows Explorer with the keyboard shortcuts.
    If the source image is on a web page right-click and use Copy Image rather than copy. (With Chrome I get a one pixel wraparound so tend to go for a temporary local copy anyway - not sure whose bug this is, but it isn't new.)
    If you have multiple images embedded drag the one you want to be the primary artwork to the leftmost position.
    Replace/Remove All Artwork
    The top left image box can be used to add or delete art from multiple tracks. In either case all existing artwork in all tracks is replaced/removed.
    Old Style Get Info Dialog
    Select some items, right-click, hold down shift, then click Get Info from the context menu. (Use alt/option on a Mac)
    tt2

  • Apple wireless keyboard won't let me delete without using the fn key.

    My apple wireless keyboard won't let me delete in indesign without using the fn key. Is there a key command that I accidentally hit that causes that or something? I've never had this happen before. It isn't happening in any other program, just indesign cs4. Has anyone had this happen and how do I fix it?

    I figured it out. My keyboard shortcut set in indesign was corrupt. I went back to the default set and created a new set and the delete key started working again.

Maybe you are looking for

  • Error VMware Tools Installation (Shared Folder) - Ubuntu 15.04 [SOLVED!]

    Workstation 11.1 Ubuntu 15.04 Guest OS Kernel 3.19.0-15-generic VMwareTools-9.9.2-2496486 When I try to install vmwaretools in my Ubuntu 15.04, I receive the following compilation errors (shared folder feature don't work): Initializing... Making sure

  • Display bug in the Flash update (10.0.2)

    So I installed the Flash CS4 update that was released in May and for the most part I'm happy with the changes.  There's at least one huge bug, though: the display doesn't update correctly when the start frame is changed on a graphic symbol via any me

  • How to adjust volume of Airport Express speakers on Apple TV?

    Hello, I've just setup my Apple TV (bought in November 2012). The latest version of the firmware allows to select AirPort Express speakers as default audio output. This is great. While watching Youtube videos or listening iTunes music, I can't find h

  • Capture @@ROWCOUNT for all QUERIES using SQL AUDIT

    I have a requirement where the customer wants to audit all SELECT queries made to a specific table  and also capture "No of rows returned" for these queries made to the table. I was able to capture various SELECT queries happening in the database /Ta

  • Date operators not woking as expected???

    Select * from scott where date>'2003-SEP-01'; I want to get all records for Sep 2, 3, 4... and so on. So why does it return records with dates that are before Sep 1, that is, Aug 31, June 1, Jan25, etc... You get the idea? I want dates that are great