定义 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. FBX导入错误 :ImportFBX Errors:

    原地址:http://www.cnblogs.com/lopezycj/archive/2012/05/16/unity3d_tuchao.html Unity3D吐槽1--FBX导入 Unity3d ...

  2. 实用且免费API接口2

    之前已经整理过一些免费API,现在在知乎专栏上看到别人整理的一些实用免费API,有一些是没有重复的,因此也搬过来. 今天的内容,很适合你去做一些好玩.实用的东西出来. 先来科普个概念,开放应用程序的A ...

  3. JavaScript——中的prototype(原型)

    JS中的prototype是JS中比较难理解的一个部分 本文基于下面几个知识点: 1 原型法设计模式 在.Net中可以使用clone()来实现原型法 原型法的主要思想是,现在有1个类A,我想要创建一个 ...

  4. pcap学习

    #include <pcap.h> char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *pcap_open_live(const char *device, in ...

  5. mui 跨域请求

    <ul class="mui-table-view" style="margin-top: 25px;"> <li class="m ...

  6. mariadb mysql 报'Access denied for user 'root'@'localhost' (using password: NO)'错误的解决

    C:\Program Files\MariaDB 10.2\bin>mysql admin -u root password "x123456789" mysql Ver 1 ...

  7. MSP430WARE++的使用3:modbus模块的调用方法

    MSP430WARE++的使用3:modbus模块的调用方法     MSP430WARE是一套基于C++语言的开源的MSP430层次化软件架构,支持多种外设. 本文将介绍modbus模块驱动程序的调 ...

  8. 李洪强iOS下的实际网络连接状态检测

    iOS下的实际网络连接状态检测 序言 网络连接状态检测对于我们的iOS app开发来说是一个非常通用的需求.为了更好的用户体验,我们会在无网络时展现本地或者缓存的内容,并对用户进行合适的提示.对绝大部 ...

  9. angularjs 可以加入html标签方法------ng-bind-html的用法总结(2)

    angular-ngSanitize模块-$sanitize服务详解 本篇主要讲解angular中的$sanitize这个服务.此服务依赖于ngSanitize模块. 要学习这个服务,先要了解另一个指 ...

  10. CI框架基本配置/教你学习CI框架codelgniter

    CI框架现在中国可以说还是不成熟,不像thinkphp那样有那么多的中文手册,在国内,很多国人英语都很烂,CI现在教程还是不多.大家心里都存在这严重想法 CI 框架现在中国可以说还是不成熟,不像thi ...