运行 带有嵌入式 Jetty 的 Web 应用程序 (WAR)

Running a web application (WAR) with embedded Jetty

我有一个 java war 正在通过 Jetty 运行。多年来,它一直在多台 Windows 7 台计算机上工作。但是现在 Windows 7 计算机上的新安装会产生错误,我不明白这些错误。我在日志下方发布直到错误点:

C:\Users\QT\Desktop\vcctl\scripts>cd ..\src

C:\Users\QT\Desktop\vcctl\src>java -classpath "lib/derby.jar:lib/derbytools.jar" -Dorg.eclipse.jetty.server.Request.maxFormKeys=20000 -jar "VcctlWrapper.jar"
2016-03-21 15:42:11.866:INFO::AWT-EventQueue-0: Logging initialized @204ms
Current relative path is: C:\Users\QT\Desktop\vcctl\src
2016-03-21 15:42:11.969:INFO:oejs.Server:AWT-EventQueue-0: jetty-9.1.3.v20140225

Mar 21, 2016 3:42:13 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/C:/Users/QT/AppData/Local/Temp/jetty-0.0.0.0-8080-vcctl.war-_vcctl-any-7374762875405590280.dir/webapp/WEB-INF/lib/struts-tiles-1.3.8.jar!/org/apache/struts/tiles/chain-config.xml
Mar 21, 2016 3:42:13 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/C:/Users/QT/Desktop/vcctl/src/lib/struts-tiles-1.3.8.jar!/org/apache/struts/tiles/chain-config.xml
Mar 21, 2016 3:42:13 PM org.apache.struts.config.impl.ModuleConfigImpl addAction Config
WARNING: Overriding ActionConfig of path /my-files/viewImage
Mar 21, 2016 3:42:13 PM org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
2016-03-21 15:42:13.626:INFO:oejsh.ContextHandler:AWT-EventQueue-0: Started o.e.j.w.WebAppContext@3c6dee0f{/vcctl,file:/C:/Users/QT/AppData/Local/Temp/jetty-0.0.0.0-8080-vcctl.war-_vcctl-any-7374762875405590280.dir/webapp/,AVAILABLE}{C:\Users\QT\Desktop\vcctl\src/vcctl.war}
2016-03-21 15:42:13.635:WARN:oejuc.AbstractLifeCycle:AWT-EventQueue-0: FAILED ServerConnector@3ba4f2fd{HTTP/1.1}{0.0.0.0:8080}: java.net.BindException: Address already in use: bind
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:279)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:218)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.server.Server.doStart(Server.java:337)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at vcctl.webServiceRunner.startJettyServer(webServiceRunner.java:98)
    at vcctl.webServiceRunner.<init>(webServiceRunner.java:40)
    at vcctl.webServiceRunner.run(webServiceRunner.java:107)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access0(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
2016-03-21 15:42:13.639:WARN:oejuc.AbstractLifeCycle:AWT-EventQueue-0: FAILED org.eclipse.jetty.server.Server@4a4cdea2: java.net.BindException: Address already
in use: bind
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:279)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:218)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.server.Server.doStart(Server.java:337)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at vcctl.webServiceRunner.startJettyServer(webServiceRunner.java:98)
    at vcctl.webServiceRunner.<init>(webServiceRunner.java:40)
    at vcctl.webServiceRunner.run(webServiceRunner.java:107)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access0(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.awt.EventQueue.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

在我的其他 Windows 7 台计算机上,日志消息如下所示:

C:\Users\bullard\Desktop\vcctl\scripts>cd ..\src

C:\Users\bullard\Desktop\vcctl\src>java -classpath "lib/derby.jar:lib/derbytools.jar" -Dorg.eclipse.jetty.server.Request.maxFormKeys=20000 -jar "VcctlWrapper.jar"
2016-03-21 17:34:04.520:INFO::AWT-EventQueue-0: Logging initialized @172ms
Current relative path is: C:\Users\bullard\Desktop\vcctl\src
2016-03-21 17:34:04.598:INFO:oejs.Server:AWT-EventQueue-0: jetty-9.1.3.v20140225
Mar 21, 2016 5:34:05 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/C:/Users/bullard/AppData/Local/Temp/jetty-0.0.0.0-8080-vcctl.war-_vcctl-any-9120726856785823814.dir/webapp/WEB-INF/lib/struts-tiles-1.3.8.jar!/org/apache/struts/tiles/chain-config.xml
Mar 21, 2016 5:34:05 PM org.apache.struts.action.ActionServlet initChain
INFO: Loading chain catalog from jar:file:/C:/Users/bullard/Desktop/vcctl/src/lib/struts-tiles-1.3.8.jar!/org/apache/struts/tiles/chain-config.xml
Mar 21, 2016 5:34:05 PM org.apache.struts.config.impl.ModuleConfigImpl addAction Config
WARNING: Overriding ActionConfig of path /my-files/viewImage
Mar 21, 2016 5:34:05 PM org.apache.struts.tiles.TilesPlugin initDefinitionsFactory
INFO: Tiles definition factory loaded for module ''.
2016-03-21 17:34:05.955:INFO:oejsh.ContextHandler:AWT-EventQueue-0: Started o.e.j.w.WebAppContext@1ac6103{/vcctl,file:/C:/Users/bullard/AppData/Local/Temp/jetty-0.0.0.0-8080-vcctl.war-_vcctl-any-9120726856785823814.dir/webapp/,AVAILABLE}{C:
\Users\bullard\Desktop\vcctl\src/vcctl.war}
2016-03-21 17:34:05.971:INFO:oejs.ServerConnector:AWT-EventQueue-0: Started ServerConnector@146eb1b{HTTP/1.1}{0.0.0.0:8080}
2016-03-21 17:34:05.971:INFO:oejs.Server:AWT-EventQueue-0: Started @1623ms

当另一个 Jetty 实例或另一个进程正在 运行 连接到您的 Jetty 服务器试图 运行 的同一端口时,就会发生这种情况。默认端口 8080 上的 Jetty 运行s。因此,要么你有另一个 Jetty 实例,要么可能是 Tomcat 服务器 运行 在该服务器上占用端口 8080(或你配置的任何端口)。

您可以修改 jetty.xml 文件并通过更改此行来更新 jetty.port

<Set name="port"><SystemProperty name="jetty.port" default="80"/></Set>

但在此之前,我会检查 taskmgr 中的进程,例如码头或 tomcat 当前 运行ning。您还可以检查 netstat -a -b 以获取 运行ning 进程及其使用的端口。