[Jetty]基于Java Servlet的支持WebSocket的服务器

1. JDK安装

www.java.com/zh/download

2. Jetty下载与安装

download.eclipse.org/jetty,下载稳定版,解压到目标路径

2.1 启动Jetty

命令框中cd到根目录下,会看到有个start.jar启动文件,在该目录下,输入 java -jar start.jar

如果顺利的话,会输出以下log:

2012-10-22 16:02:24.988:INFO:oejs.Server:main: jetty-9.0.0-M2 
2012-10-22 16:02:25.040:INFO:oejs.NCSARequestLog:main: Opened /home/gregw/src/jetty-9/jetty-distribution/target/distribution/logs/2012_10_22.request.log
2012-10-22 16:02:25.115:INFO:oejs.ServerConnector:main: Started ServerConnector@6aeeafb{HTTP/1.1}{0.0.0.0:8080} 
2012-10-22 16:02:25.348:INFO:oejs.ServerConnector:main: Started ServerConnector@24a45e{SSL-http/1.1}{0.0.0.0:8443} 
2012-10-22 16:02:25.357:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/home/gregw/src/jetty-9/jetty-distribution/target/distribution/webapps/] at interval 1 
2012-10-22 16:02:25.688:INFO:oejd.DeploymentManager:main: Deployable added:/home/gregw/src/jetty-9/jetty-distribution/target/distribution/webapps/test.xml 
2012-10-22 16:02:25.725:INFO:oejw.WebInfConfiguration:main: Extract jar:file:/home/gregw/src/jetty-9/jetty-distribution/target/distribution/webapps/test.war!/ to /tmp/jetty-0.0.0.0-8080-test.war-_test-any-/webapp
2012-10-22 16:02:26.097:INFO:oejsh.ContextHandler:main: started o.e.j.w.WebAppContext@4e3ceb07{/test,file:/tmp/jetty-0.0.0.0-8080-test.war-_test-any-/webapp/,AVAILABLE}{/test.war}
=========================================================================
途中如果输出以下信息:
java.net.BindException: Address already in use 
  at sun.nio.ch.Net.bind0(Native Method) 
  at sun.nio.ch.Net.bind(Net.java:344) 
  at sun.nio.ch.Net.bind(Net.java:336) 
  at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
那么说明是port出现了冲突,默认jetty的端口号是8080,那么就把正在使用该端口号的应用关闭,或者通过以下方式,修改jetty的默认端口8080。
 java -jar start.jar jetty.port=8081
==========================================================================
可以输入
java -jar start.jar --help
寻求帮助
==========================================================================
也可输入以下内容,开启HTTP服务

> java -jar start.jar etc/jetty-https.xml

在浏览器中输入 https://localhost:8443/来验证

==========================================================

 

[Jetty]基于Java Servlet的支持WebSocket的服务器,布布扣,bubuko.com

[Jetty]基于Java Servlet的支持WebSocket的服务器

上一篇:java序列化Serializable那些事


下一篇:Eclipse开发C/C++ 安装配置图文详解