定义 jetty.xml 启动文件 

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Get name="ThreadPool">
<Set name="minThreads" type="int">10</Set>
<Set name="maxThreads" type="int">100</Set>
<Set name="idleTimeout" type="int">60000</Set>
<Set name="detailedDump">false</Set>
</Get>

<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler" />
</Arg>
</Call>

<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ServerConnector">
<Arg>
<Ref refid="Server"></Ref>
</Arg>
<Set name="port">8899</Set>
<Set name="connectionFactories">
<Array type="org.eclipse.jetty.server.ConnectionFactory">
<Item>
<New class="org.eclipse.jetty.server.HttpConnectionFactory"></New>
</Item>
</Array>
</Set>
<Set name="idleTimeout">30000</Set>
<!-- <Set name="lowResourceMaxIdleTime">3000</Set> <set name="lowResourcesConnections">90</set>
<Set name="acceptors">1</Set> -->
</New>
</Arg>
</Call>

<Set name="handler">
<New class="org.eclipse.jetty.server.handler.StatisticsHandler">
<Set name="handler">
<New class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts"
class="org.eclipse.jetty.server.handler.ContextHandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New class="org.eclipse.jetty.servlets.gzip.GzipHandler">
<Set name="mimeTypes">text/html,text/xml,application/json,text/plain,application/xhtml+xml,text/css,application/javascript,image/svg+xml
</Set>
<Set name="minGzipSize">0</Set>
<Set name="handler">
<New class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="war">./web</Set>
<Call name="setInitParameter">
<Arg>org.eclipse.jetty.servlet.Default.dirAllowed
</Arg>
<Arg>false</Arg>
</Call>
</New>
</Set>
</New>
</Item>
</Array>
</Set>
</New>
</Item>

<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler" />
</Item>

<Item>
<New class="org.eclipse.jetty.server.handler.RequestLogHandler">
<Set name="requestLog">
<New class="org.eclipse.jetty.server.NCSARequestLog">
<Set name="filename">
logs/yyyy_mm_dd.jetty_request.log
</Set>
<Set name="filenameDateFormat">yyyy_MM_dd</Set>
<Set name="LogTimeZone">GMT</Set>
<Set name="retainDays">90</Set>
<Set name="append">true</Set>
<Set name="logLatency">true</Set>
</New>
</Set> 
</New>
</Item>
</Array>
</Set>
</New>
</Set>
</New>
</Set>
</Configure>

  

定义jetty启动类

Jetty.java

   

public class Jetty {
private Server server;

public Jetty() throws Exception {
Resource fileserver_xml = Resource.newClassPathResource("jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
server = (Server) configuration.configure();
}

public Jetty(String config) throws Exception {
Resource fileserver_xml = Resource.newClassPathResource(config);
XmlConfiguration configuration = new XmlConfiguration(fileserver_xml.getInputStream());
server = (Server) configuration.configure();
}

public void startup() throws Exception {
try {
server.start();
} catch (Exception e) {
throw e;
}
try {
server.join();
} catch (InterruptedException e) {
throw e;
}
}

public void shutdown() throws Exception {
server.stop();
}

public static void main(String[] args) throws Exception {
Jetty jetty = new Jetty();
jetty.startup();
}

}

 

WEB 结构

bin  etc  lib  logs  web

web中文件内容同tomcat 类似

jetty 通过配置文件嵌入式启动web服务的更多相关文章

  1. Eclipse使用Maven jetty/tomcat:run命令启动web项目

    Eclipse安装好m2e插件,使用Maven构建项目后,启动web项目就行就非常简单了,如下所示. 操作步骤: 1.右键你的项目 -> Run As -> Run Configurati ...

  2. 008-插件方式启动web服务tomcat,jetty

    一.pom引入 1.tomcat7 <!-- tomcat7 --> <plugin> <groupId>org.apache.tomcat.maven</g ...

  3. 打印机威胁:嵌入式Web服务有安全问题

    现在大多数打印机.扫描仪,以及VoIP系统等设备都会内建嵌入式的Web服务,这主要是为了方便管理.然而不幸的是,这些设备大多会由于设置问题而处在无保护状态下.有些服务甚至可以使用默认的帐号和密码访问, ...

  4. 【Python】 最简单的web服务

    python -m SimpleHTTPServer  8321 1.python 没有指定目录的参数 想启动目录 就cd到该目录下 2.在目录下创建一个index.html 3.启动web服务,(端 ...

  5. 使用Autofac动态注入启动Api服务

    Autofac Autofac(https://autofac.org/)是一款.NET的IOC组件,它可以和Owin, Web Api, ASP.NET MVC, .NET Core完美结合,帮助开 ...

  6. windows + myeclipse 调试 linux + tomcat 的java web服务 配置方式

    一.linux tomcat配置和启动 1.catalina.sh第一行加入 declare -x CATALINA_OPTS="-Xdebug -Xrunjdwp:transport=dt ...

  7. idea/eclipse下Maven工程集成web服务(tomcat、jetty)

     idea/eclipse下Maven工程集成web服务 转载请注明出处:http://www.cnblogs.com/funnyzpc/p/8093554.html 应用服务器最常用的一般有这哥仨: ...

  8. Web服务(Apache、Nginx、Tomcat、Jetty)与应用(LAMP、CMS-WordPress&Ghost、Jenkins、Gitlab)

    Web服务和应用是目前信息技术领域的热门技术.如何使用Docker来运行常见的Web服务器(包括Apache.Nginx.Tomcat等),以及一些常用应用(LAMP.CMS等).包括具体的镜像构建方 ...

  9. Jetty实战之 嵌入式Jetty运行web app

    Jetty实战之 嵌入式Jetty运行web app 博客分类: 应用服务器 jettywar  转载地址:http://blog.csdn.net/kongxx/article/details/72 ...

随机推荐

  1. XYWi-Fi v2.0 简单的笔记本无线热点分享工具【Win】

    [软件名称]XYWi-Fi [版本号]v2.0 [适用系统]Windows 7/8/8.1/10 [功能特性]简单的笔记本无线热点分享工具 [下载地址]pan.baidu.com/s/1mgmOpJi ...

  2. 预装WIN8改装WIN7之BIOS设置

    不少预装WIN8/10的朋友觉得WIN8/10不好用,想改装WIN7,可改装之后常常出现各种问题,甚至不能启动,往往是BIOS设置不当. 本文以联想小新V2000 预装WIN8.1中文版为例,说说WI ...

  3. AngularJs学习笔记(3)——scope

    AngularJS启动并生成视图时,会将根ng-app元素同$rootScope进行绑定. $rootScope是所有$scope对象的最上层,是AngularJS中最接近全局作用域的对象 . 一个n ...

  4. CentOS7中关闭selinux

    在安装Cobbler和Puppet时需要关闭selinux,但是通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态, 如下所示: [csharp] view plaincopy   ...

  5. Atitit.常用语言的常用内部api 以及API兼容性对源码级别可移植的重要性 总结

    Atitit.常用语言的常用内部api 以及API兼容性对源码级别可移植的重要性 总结 1.1. 要兼容的重要语言api1 1.2. 常用基础api分类 core api1 1.3. 比较常用的扩展库 ...

  6. CSS3主要知识点复习总结+HTML5新增标签

    文件夹: 1.CSS 属性编写顺序 2.CSS3属性(内核前缀) 3.position相对/绝对定位 4.overflow:scroll等的差别 5.display属性应用 6.盒模型计算方法和Bug ...

  7. Linux下查看硬件信息的方法

    用硬件检测程序kuduz探测新硬件:service kudzu start ( or restart) 查看CPU信息:cat /proc/cpuinfo 查看板卡信息:cat /proc/pci 查 ...

  8. 如何获取wifi名称(SSID)

    @import SystemConfiguration.CaptiveNetwork; /** Returns first non-empty SSID network info dictionary ...

  9. 虚机下Ubuntu与Win7文件共享

    使用Samba服务实现虚机与本机的文件共享,简单的分为以下几个步骤,按部就班,so easy 1.安装smb sudo apt-get install samba sudo apt-get insta ...

  10. 【ASP.NET】——AdRotator控件

    AdRotator控件即广告控件. 广告,是站点不可缺少的一部分.也是站点获取收益的最主要途径,但最初制作广告非常麻烦.asp.net就将该方法封装成了一个控件.为我们节省了非常多时间.这也是ASP. ...