title: dynamically adding servlet from external file, Tomcat7
body: <p>I'm trying to dynamically add a servlet from an external file (compiled .class file) running tomcat7 server</p>
  
  <p>here's my code </p>
  
  <pre><code>import javax.servlet.ServletContext;
  import javax.servlet.ServletContextEvent;
  import javax.servlet.ServletContextListener;
  import javax.servlet.ServletRegistration;
  
  import com.sun.org.apache.bcel.internal.util.ClassLoaderRepository;
  
  
  
  public class ConListenerImlp implements ServletContextListener{
  
  
      @Override
      public void contextDestroyed(ServletContextEvent arg0) {
  
      }
  
      @Override
      public void contextInitialized(ServletContextEvent arg0) {
          ServletContext context =  arg0.getServletContext();
          final ServletRegistration.Dynamic dn=context.addServlet("test","C:\\Users\\Learning\\workspace\\Server\\build\\classes\\Test.class");
          dn.setAsyncSupported(true);
          dn.addMapping("/test");
  
  
  
      }
  
  
  }
  </code></pre>
  
  <p>when i call servlet "test" I get a ClassNotFoundException </p>
  
  <pre><code>java.lang.ClassNotFoundException: C:\Users\Learning\workspace\Server\build\classes\Test.class
  </code></pre>
  
  <p>any help would be very appreciated </p>