Search code examples
javamavenintellij-ideamaven-jetty-plugin

How to fix an issue with maven-jetty plugin that restarts my servlet every minute?


I am following a java - Android course, and on the last chapter of the basic level, they are talking about the setup of servlet with maven-jetty plugin. I was doing exactly as they said, but I'm not able to run my servlet on localhost:8080. The project is just a simple HelloWorld style, but the problem is that I'm having failure to run the sever. I am using Intellij IDE

I'm using the jetty plugin on my pom.xml

<plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.15.v20190215</version>
                <configuration>
                    <scanIntervalSeconds>1</scanIntervalSeconds>
                </configuration>
            </plugin>

and that is my web.xml file

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <sevlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>com.elie.webapp.project.web.HelloWorldServlet</servlet-class>
    </sevlet>

    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
</web-app>

and my java class to show the String "Hello World"

package com.elie.webapp.project.web;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HelloWorldServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().println("Hello World");
    }
}

When I execute jetty:run plugin, it seems like everything goes well and I receive on the log:

[INFO] Web overrides =  none
[INFO] web.xml file = null
[INFO] Webapp directory = C:\Users\Elie\IdeaProjects\webapp\target\webapp-tmp
[INFO] jetty-9.4.15.v20190215; built: 2019-02-15T16:53:49.381Z; git: eb70b240169fcf1abbd86af36482d1c49826fa0b; jvm 11.0.2+9-LTS
[INFO] Scanning elapsed time=65ms
[INFO] DefaultSessionIdManager workerName=node0
[INFO] No SessionScavenger set, using defaults
[INFO] node0 Scavenging every 660000ms
[INFO] Started o.e.j.m.p.JettyWebAppContext@52ae997b{/,file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/,AVAILABLE}{file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/}
[INFO] Started ServerConnector@65002c76{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[INFO] Started @4744ms
[INFO] Started Jetty Server

And 10 seconds after that message, the server restarting itself over and over again with the following message

[INFO] restarting o.e.j.m.p.JettyWebAppContext@52ae997b{/,file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/,AVAILABLE}{file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/}
[INFO] Stopped o.e.j.m.p.JettyWebAppContext@52ae997b{/,file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/,UNAVAILABLE}{file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/}
[INFO] Webapp source directory = C:\Users\Elie\IdeaProjects\webapp\target\webapp-tmp
[INFO] Reload Mechanic: automatic
[INFO] nonBlocking:false
[INFO] Classes = C:\Users\Elie\IdeaProjects\webapp\target\classes
[INFO] Context path = /
[INFO] Tmp directory = C:\Users\Elie\IdeaProjects\webapp\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = null
[INFO] Webapp directory = C:\Users\Elie\IdeaProjects\webapp\target\webapp-tmp
[INFO] Scanning elapsed time=42ms
[INFO] Started o.e.j.m.p.JettyWebAppContext@52ae997b{/,file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/,AVAILABLE}{file:///C:/Users/Elie/IdeaProjects/webapp/target/webapp-tmp/}
[INFO] Restart completed at Wed Apr 03 10:52:48 CEST 2019


Solution

  • You may configure it like this:

    <configuration>
       <reload>manual</reload>
    </configuration>
    

    reload Default value is "automatic", used in conjunction with a non-zero scanIntervalSeconds causes automatic hot redeploy when changes are detected. Set to "manual" instead to trigger scanning by typing a linefeed in the console running the plugin. This might be useful when you are doing a series of changes that you want to ignore until you’re done. In that use, use the reload parameter.