定义 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. openerp-server.conf 中配置 dbfilter 参数无效的解决办法

    来自:http://shine-it.net/index.php/topic,14517.html 以前就发现过这个问题, 今天重新在群里同大家讨论了一下. 有时候可能我们希望用户不从登陆界面的账套选 ...

  2. css3的Background新属性

    前言 CSS3中出现了几种关于背景图片的新属性:background-origin.background-clip.background-position等.之前大致了解了下,但是background ...

  3. android推送方式

    本文介绍在Android中实现推送方式的基础知识及相关解决方案.推送功能在手机开发中应用的场景是越来起来了,不说别的,就我们手机上的新闻客户端就时不j时的推送过来新的消息,很方便的阅读最新的新闻信息. ...

  4. 深入分析JavaWeb Item22 -- 国际化(i18n)

    一.国际化开发概述 软件的国际化:软件开发时,要使它能同一时候应对世界不同地区和国家的訪问,并针对不同地区和国家的訪问.提供对应的.符合来訪者阅读习惯的页面或数据. 国际化(international ...

  5. Eclipse RCP应用开发(概念)

    学习Eclipse RCP应用开发,对其中一些相关的概念需要了解. 让我们在讲解概念前先思考两个问题. 问题一.什么是Eclipse 大部分同学会回答eclipse是IBM公司开发的java集成开发环 ...

  6. Boolean 转 string

    boolean b=false; String b= String.valueOf(b);

  7. 配置AutoMapper映射规则《转》

    配置AutoMapper映射规则 AutoMapper是基于约定的,因此在实用映射之前,我们需要先进行映射规则的配置. public class Source { public int SomeVal ...

  8. 开发GPIO驱动的基本套路

    最近完成了基于AR9331的GPIO驱动的开发,主要包括:控制一个连接GPIO的灯控:接收一个连接GPIO的按键事件:以及接收一个连接GPIO的脉冲事件. 这里,结合开发实践,总结一下GPIO驱动开发 ...

  9. IOS设计模式浅析之适配器模式(Adapter)

    引言 在项目开发中,有时候会遇到这样的一种情景:需要使用以前开发的“一些现存的对象”,但是新环境中要求的接口是这些现存对象所不满足的.怎样应对这种迁移的需求?使得可以复用这些对象,以满足新的应用环境, ...

  10. 十年WEB技术发展历程

    一个小分享,知识有限,抛砖引玉. ajax 03年的时候我上六年级,那时候网吧刚在小县城的角落萌生.传奇,大话西游第一代网游一时风靡.我抱着试一试的心态给了网吧老板两块钱想申请个号玩玩,然后接下来的一 ...