Hi all,

A question, I can't solve that....

Tested with Tomcat 9.0.41, java 8 x64, linux (Fedora 32).


I have a standard tomcat web.xml (3.0 or 3.1, no matter).

I have created an external simple servlet with @WebServlet annotation, and packaged it to a jar file:


@WebServlet(name = "TestServlet", urlPatterns = {"/TestServlet"}, loadOnStartup 
= 1)
public class TestServlet extends HttpServlet {

    private static final Logger log = 
Logger.getLogger(TestServlet.class.getName());

    private static final long serialVersionUID = 1L;

    @Override
    public void init() throws ServletException {
        log.setLevel(Level.ALL);
        log.log(Level.WARNING, "TESTSERVLET INIT");
        super.init();
    }

    @Override
    public void destroy() {
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
        processRequest(req, resp);
    }

    protected void processRequest(HttpServletRequest request, 
HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        try {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet TestServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet TestServlet at " + request.getContextPath() + 
"</h1>");

            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

}


So, if I copy the .jar file inside WEB-INF/lib folder of destination war project the log message will appears and the servlet is reachable.

But, if I copy the .jar file inside tomcat/lib folder the annotation won't be processed.


FYI, in tomcat 7 both cases (inside WEB-INF/lib and tomcat/lib) works well.


I searched on breaking changes between tomcat 7 and 8/8.5/9 but nope. Seems related to jarscanner.....but no luck!


Because my servlet is in common to all projects I want to put it inside tomcat/lib folder and share it to all my projects


Somebody can help me?


Many thanks,

Agharta





Reply via email to