定义 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. PJOI PKU Campus 2011 B:A Problem about Tree LCA 求随意点x为根的y的父节点

    题目链接:点击打开链接 题意:给定n个点 m个询问 以下n-1行给定一棵树 m个询问 x y 问把树转成以x为根 y的父节点是谁 第一种情况lca==y那就是x的第 dep[x] - dep[y] - ...

  2. win7系统扩展双屏幕时,怎样在两个屏幕下都显示任务栏

    扩展屏幕下都显示任务栏!!! win7系统本身无法设置该功能(眼下我是不知道) 但能够下载第三方软件来解决该问题. 第一步:Dual Monitor Taskbar 下载软件 下载链接:http:// ...

  3. BIEE-CSS样式大全

    字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...

  4. HTML5之坦克大战游戏开发

    1.在使用arc方法进行画圆时,在IE9+,FF,Safari,Chrome等已经支持HTML5标准的浏览器中进行渲染时,采用逆时针方向画时,也就是说 arc(x, y, radius, startA ...

  5. URL.createObjectURL()

    URL.createObjectURL() 静态方法会创建一个 DOMString,其中包含一个表示参数中给出的对象的URL.这个 URL 的生命周期和创建它的窗口中的 document 绑定.这个新 ...

  6. usb转串口模块下载时遇到的问题

    ch340g usb转TTL模块,烧写wifi模块ESP8266固件时,为图省事,我直接用的该模块的3.3v电为wifi模块供的电,结果刚一上电就出现串口模块消失(听到噔的一声),电脑设备管理器里就看 ...

  7. eslint 人性化配置

    错误列表: http://www.zystudios.cn/blog/post/70.Shtml 人性化一点.别老虐我啊晓梦大师 module.exports = { root: true, pars ...

  8. vivado2016.2下系统自带DDR3 ip例程仿真运行

    背景:从ISE14.7迁移到vivado2016.2. xilinx的软件改的真是不一般的大.两个软件操作差距真是让人想骂人.由于项目需要,准备调试DDR3.对于新手来说,例化一个DDR3 ip.如果 ...

  9. 下载文件,ie文件名称乱码问题

    设置响应编码,将文件名称用java.net.URLEncoder.encode编码,这样就不会乱码了 java.net.URLEncoder.encode response.setCharacterE ...

  10. Angularjs学习笔记2_添加删除DOM元素

    1.调用element方法     angular.element(html) 把字符串或dom对象转化成一JQuery对象, angular.element(document.getElementB ...