1 Reply Latest reply: Apr 18, 2010 10:13 PM by DrClap RSS

    Reloading class via ClassLoader not working

    843798
      Hey guys,
      I'm using ClassLoader via URLClassLoader (from a jar file), and then loading the class i need.
      When the jar file is changed i try to reload the class i need from the new jar but it does not work.
      What am i doing wrong? Is there another way to replace classes in runtime?
      private void createClassLoader()
          {
              File jarFile = new File(EXTERNAL_DOWNLOADERS_JAR);
              if (!jarFile.exists())
              {
                  return;
              }
              
              try 
              {
                  URL[] urls = {new URL("file://" + EXTERNAL_DOWNLOADERS_JAR)};
                  classLoader = new URLClassLoader(urls);
                  log.log(Level.INFO, "Created class loader " + classLoader);
              } 
              catch (MalformedURLException e)
              {
                  log.log(Level.WARNING, "Problem creating class loader: ", e);
              }
          }
      This segment works only at first load but i cannot replace the extDownloader
      Class<?> temp = PersistencyManager.classLoader.loadClass(EXT_DOWNLOADER_PATH + extDownloaderName);
      extDownloader = (ExtDownloader) temp.newInstance();
      extDownloader.setSiteInfo(siteInfo);