1 Reply Latest reply on Jun 16, 2005 10:17 AM by Joern

    how to load a class with ClassLoader outside from repository

    Joern Newbie


      i need to load a class at runtime that is not in my war-file, is that possible? the classloader always looks in WEB-INF/classes but the class i want to load is in another directory and i cant move that file(s) always in my war-archive and rebuild it. Is it possible to configure jboss/tomcat for this? Configure the classpath didnt work.

      thanks a lot!

        • 1. Re: how to load a class with ClassLoader outside from reposi
          Joern Newbie

          i used this in my servlet, i set a new Loader(new path) with the current as parent:

          URLClassLoader parentLoader = null, scriptletLoader = null;

          Object currentloader = Thread.currentThread().getContextClassLoader();
          if (currentloader instanceof URLClassLoader) parentLoader = (URLClassLoader)currentloader;
          scriptletLoader = new URLClassLoader(new URL[]{ new URL(new File(homeDir + System.getProperty("file.separator")).toURL().toString())}, parentLoader);

          is that a "good" solution? can something going wrong if i set a new loader? is there a better way?