如何解决每分钟重新启动我的 servlet 的 maven-jetty 插件的问题?
How to fix an issue with maven-jetty plugin that restarts my servlet every minute?
我正在学习 java - Android 课程,在基础级别的最后一章,他们正在谈论使用 maven-jetty 插件设置 servlet。
我完全按照他们说的做了,但是我无法 运行 我的 servlet on localhost:8080。
该项目只是一个简单的 HelloWorld 样式,但问题是我无法 运行 服务器。
我正在使用 Intellij IDE
我在 pom.xml
上使用 jetty 插件
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.15.v20190215</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
</configuration>
</plugin>
那是我的 web.xml 文件
<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>
和我的 java class 来显示字符串 "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");
}
}
当我执行 jetty:run 插件时,似乎一切顺利,我在日志中收到:
[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
在该消息 10 秒后,服务器一次又一次地重新启动自身并显示以下消息
[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
您可以这样配置:
<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.
我正在学习 java - Android 课程,在基础级别的最后一章,他们正在谈论使用 maven-jetty 插件设置 servlet。 我完全按照他们说的做了,但是我无法 运行 我的 servlet on localhost:8080。 该项目只是一个简单的 HelloWorld 样式,但问题是我无法 运行 服务器。 我正在使用 Intellij IDE
我在 pom.xml
上使用 jetty 插件<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.15.v20190215</version>
<configuration>
<scanIntervalSeconds>1</scanIntervalSeconds>
</configuration>
</plugin>
那是我的 web.xml 文件
<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>
和我的 java class 来显示字符串 "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");
}
}
当我执行 jetty:run 插件时,似乎一切顺利,我在日志中收到:
[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
在该消息 10 秒后,服务器一次又一次地重新启动自身并显示以下消息
[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
您可以这样配置:
<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.