简体   繁体   中英

use @WebServlet annotation in maven jetty plugin

I build an web application in my ecplise with maven plugin I want debug it in jetty.

@WebServlet(name="Startup",value="/", urlPatterns = {}, loadOnStartup = 1)
public class Startup extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see Servlet#init(ServletConfig)
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("start up");
        QCloud.setupSDK();
    }

I don't know if it's your case but I faced similar issue with Jetty.

When using annotations the web.xml file is not needed anymore, so if you have it then remove it (even if there are no servlets mapped inside) and it will make the trick.

Also note that either value or urlPatterns are required attributes for @WebServlet annotation but you shouldn't use both at the same time.

This Github issue mentions that servlet API moved packages from javax.*<\/code> to jakarta.*<\/code> . Only Jetty 11 and later changed to reading annotations from jakarta<\/code> . Perhaps, your code uses the newer jakarta servlet API and older Jetty 9.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM