I’m having trouble getting a simple Java servlet to run under tomcat7 (fresh install from ubuntu repository).
It is a single .java file with @WebServlet("/TestServlet"). I put it into /var/lib/tomcat7/webapps/TestServlet/WEB-INF and would like Tomcat to recognize and automatically compile it (also, when I change the source file). How do I set this up in a simple way?
You have to compile your code using java compiler (or IDE). Then deploy
*.classfile(s) under servlet container (Tomcat in your case).The class file must be under your
WEB-INF/classesdirectory. If you class belongs to package likecom.myservletand its name isHellowServletput it into file/var/lib/tomcat7/webapps/TestServlet/WEB-INF/com/myservlet/HelloServlet.classEDIT:
if you indeed want make tomcat to compile your servlet, write JSP. This is a key feature of JSP: it can be deployed as a source code and is compiled automatically to servlet by container.