半只蚂蚁 发表于 2017-2-27 06:19:14

Jetty 入门:安装,部署第一个web application

  1 Jetty 简介


  Jetty
是一个开源的servlet容器,它为基于Java的web内容,例如JSP和servlet提供运行环境。Jetty是使用Java语言编写的,它的
API以一组JAR包的形式发布。开发人员可以将Jetty容器实例化成一个对象,可以迅速为一些独立运行(stand-alone)的Java应用提供
网络和web连接。
  Jetty 可以作为嵌入式服务器使用,Jetty的运行速度较快,而且是轻量级的,可以在Java中可以从test case中控制其运行。从而可以使自动化测试不再依赖外部环境,顺利实现自动化测试。
  Jettyis an open-source, standards-based, full-featured web
server and servlet container implemented entirely in Java. It is
released under the Apache 2.0 licence and is therefore free for commercial use and distribution.
  2 Jetty 下载安装,启动与关闭


  下载: http://jetty.mortbay.org/jetty/  目前的稳定版是 Jetty6,建议项目中使用此版本
  安装: 和zip版的tomcat几乎一样,解压到你自己的目录即可
  根目录下与操作密切相关的主要为:
  (1 start.jar用于启动jetty,最简单的方法:

java -jar startup.jar
  这种方式等同于下面的启动方式; 关闭时ctrl+c 即可 !
  Running jetty6 is as simple as going to your jetty installion directory and typing:

java -jar start.jar etc/jetty.xml



  This will start jetty and deploy a demo webapp available at:

http://localhost:8080/test





Stopping

  Apart from stopping jetty with a cntrl-cin the same terminal window as you started it, you can
start Jetty so that it listens on a local port for stop commands:

java -DSTOP.PORT=8079 -DSTOP.KEY=secret -jar start.jar



  The server can then be stopped using a different terminal window on the same machine:

java -DSTOP.PORT=8079 -DSTOP.KEY=secret -jar start.jar --stop



  If the STOP.KEY property is ommitted from the start command, then a
random key is printed on standard out. If the STOP.PORT is set to 0, a
random available port is assigned and printed on stdout.
  

  (2  webapps: 这就是部署项目的目录
  


  3 Jetty 项目部署


  (1 直接将项目文件夹放至 webapps下即可;
  (2 将项目打包为war,放至webapps下即可!
  是不是很简单呢??? 类似于tomcat,jboss ???  第一个项目都是这么简单的!
  到这里,相信我们都可以自己开发和部署了;但是关于Jetty的具体配置调整和性能调优等,还需要更进一步的学习和实践才行!
  Good Luck !
页: [1]
查看完整版本: Jetty 入门:安装,部署第一个web application