我正在尝试从运行 tomcat7 服务器的外部文件(编译的 .class 文件)动态添加 servlet
这是我的代码
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");
}
}
当我调用 servlet“测试”时,我得到一个 ClassNotFoundException
java.lang.ClassNotFoundException: C:\Users\Learning\workspace\Server\build\classes\Test.class
任何帮助将不胜感激