转载地址:http://blog.csdn.net/kongxx/article/details/7237034

要说嵌入式运行Jetty,最常用的还应该是运行一个标准的war文件或者指定一个webapp目录。

0. 首先需要添加Jetty运行时webapp的依赖包,下面是一个完整的pom.xml文件

写道
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.google.code.garbagecan.jettystudy</groupId> 
<artifactId>jettystudy</artifactId> 
<packaging>jar</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>jettystudy</name> 
<url>http://maven.apache.org</url> 
<build> 
<plugins> 
<plugin> 
<artifactId>maven-compiler-plugin</artifactId> 
<inherited>true</inherited> 
<version>2.3.1</version> 
<configuration> 
<source>1.6</source> 
<target>1.6</target> 
<debug>true</debug> 
</configuration> 
</plugin> 
</plugins> 
</build> 
<dependencies> 
<!-- Spring support --> 
<dependency> 
<groupId>org.springframework</groupId> 
<artifactId>spring</artifactId> 
<version>2.5.6</version> 
</dependency>

<!-- Jetty --> 
<dependency> 
<groupId>org.eclipse.jetty.aggregate</groupId> 
<artifactId>jetty-all</artifactId> 
<version>8.0.4.v20111024</version> 
</dependency>

<!-- Jetty Webapp --> 
<dependency> 
<groupId>org.eclipse.jetty</groupId> 
<artifactId>jetty-webapp</artifactId> 
<version>8.0.4.v20111024</version> 
</dependency>

<!-- JSP Support --> 
<dependency> 
<groupId>org.glassfish.web</groupId> 
<artifactId>javax.servlet.jsp</artifactId> 
<version>2.2.3</version> 
</dependency>

<!-- EL Support --> 
<dependency> 
<groupId>org.glassfish.web</groupId> 
<artifactId>javax.el</artifactId> 
<version>2.2.3</version> 
</dependency>

<!-- JSTL Support --> 
<dependency> 
<groupId>org.glassfish.web</groupId> 
<artifactId>javax.servlet.jsp.jstl</artifactId> 
<version>1.2.1</version> 
<exclusions> 
<exclusion> 
<artifactId>jstl-api</artifactId> 
<groupId>javax.servlet.jsp.jstl</groupId> 
</exclusion> 
</exclusions> 
</dependency> 
</dependencies> 
</project>

1. 运行标准的war文件

1.1 首先找一个完整的war包,这里使用了struts2自带的一个例子应用程序struts2-blank.war;

1.2 创建自己的Jetty Server启动类WebAppContextWithWarServer,其中指定了war文件的路径,并指定context路径为"/myapp"

  1. package com.google.code.garbagecan.jettystudy.sample6;
  2. import org.eclipse.jetty.server.Server;
  3. import org.eclipse.jetty.webapp.WebAppContext;
  4. public class WebAppContextWithWarServer {
  5. public static void main(String[] args) throws Exception {
  6. Server server = new Server(8080);
  7. WebAppContext context = new WebAppContext();
  8. context.setContextPath("/myapp");
  9. context.setWar("E:/share/test/struts2-blank.war");
  10. server.setHandler(context);
  11. server.start();
  12. server.join();
  13. }
  14. }

1.3 运行WebAppContextWithWarServer类,然后访问// http://localhost:8080/myapp/就可以看到struts2的例子界面了。

2. 运行一个webapp目录

2.1 还是用上面的struts2-blank.war,将这个war包解压后放到一个目录下;

2.2 创建自己的Jetty Server启动类WebAppContextWithFolderServer,其中指定了webapp目录,并指定context路径为"/myapp"

  1. package com.google.code.garbagecan.jettystudy.sample6;
  2. import org.eclipse.jetty.server.Server;
  3. import org.eclipse.jetty.webapp.WebAppContext;
  4. public class WebAppContextWithFolderServer {
  5. public static void main(String[] args) throws Exception {
  6. Server server = new Server(8080);
  7. WebAppContext context = new WebAppContext();
  8. context.setContextPath("/myapp");
  9. context.setDescriptor("E:/share/test/struts2-blank/WEB-INF/web.xml");
  10. context.setResourceBase("E:/share/test/struts2-blank");
  11. context.setParentLoaderPriority(true);
  12. server.setHandler(context);
  13. server.start();
  14. server.join();
  15. }
  16. }

2.3 运行WebAppContextWithFolderServer类,然后访问// http://localhost:8080/myapp/就可以看到struts2的例子界面了。

Jetty实战之 嵌入式Jetty运行web app的更多相关文章

  1. Jetty实战之 嵌入式Jetty运行Servlet

    http://blog.csdn.net/kongxx/article/details/7230080 Jetty实战之 嵌入式Jetty运行Servlet 分类:JettyJava (19530)  ...

  2. Jetty实战之 安装 运行 部署

    本文地址:http://blog.csdn.net/kongxx/article/details/7218767 1. 首先从Jetty的官方网站http://wiki.eclipse.org/Jet ...

  3. (转)Jetty实战之 安装 运行 部署

    http://blog.csdn.net/kongxx/article/details/7218767 本文地址:http://blog.csdn.NET/kongxx/article/details ...

  4. web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)

    在开发Java web项目时候,可以在项目中嵌入Jetty服务的方式来运行web程序. 由于最近开发web项目,自己使用的是比较旧的eclipse不支持导入tomcat来运行项目,于是就学习了下使用项 ...

  5. Jetty:部署到Jetty

    Web应用的框架 标准Jetty公布版本号能部署标准servlet Spec Web应用和Jetty内部ContextHandler部署描写叙述符,或者两者的一个混合. Web应用是可部署的动态(se ...

  6. html5文章 -- 使用 jQuery Mobile 与 HTML5 开发 Web App ——开发原则 | Kayo's Melody

    最近专注研究 jQuery Mobile —— 一款很方便就可以把 Web App 包装成适合 Android 与 iPhone 等触屏移动设备的 Javascript 库,结合 jQuery Mob ...

  7. Native APP ,Web APP,Hybrid APP三者对比

    Native APP Native APP 指的是原生程序(Android.iOS.WP),一般依托于操作系统,有很强的交互,可拓展性强,需要用户下载安装使用,是一个完整的App. 原生应用程序是某一 ...

  8. 【Azure 应用服务】Azure Web App的服务(基于Windows 操作系统部署)在被安全漏洞扫描时发现了TCP timestamps漏洞

    问题背景 什么是TCP timestamps(TCP 时间戳)? The remote host implements TCP Timestamps, as defined by RFC1323 (h ...

  9. 使用cmd命令创建maven(web)项目+项目转换成IDEA项目+项目打包+Jetty运行Web项目

    3条件:配置好环境 配置环境教程:https://www.cnblogs.com/weibanggang/p/9623705.html 第一步:查看版本信息,在cmd输入mvn –version,如果 ...

随机推荐

  1. Graphics.BlitMultiTap解析

    [Graphics.BlitMultiTap解析] 上述代码的四个偏移,表示利用此4个偏移,生成4张纹理单位.下面每一个SetTexture,默认会调用一个纹理单位. 而在Shader中,Unity会 ...

  2. Source命令及脚本的执行方式

    [Source命令及脚本的执行方式] source filename 与 sh filename 及./filename执行脚本的区别在那里呢? 1.当shell脚本具有可执行权限时,用sh file ...

  3. OGNL概述

    -------------------siwuxie095 OGNL 概述 1.OGNL 即 Object-Graph Navigation Language,对象图导航语言, 它是一个应用于 Jav ...

  4. vmware虚拟机开机报附件中的错误的解决办法

    Virtualized Inter VT-x/EPT is incompatible with this virtual machine configuration 在没有虚拟化msg.inter.h ...

  5. SDL编程

    一.简介 SDL是一个用C编写的跨平台的多媒体库,它通过OpenGL和Direct3D,提供了针对音频.视频.键盘.鼠标.控制杆及3D硬件的低级别的访问接口.它在MPEG播放软件.模拟器以及许多游戏中 ...

  6. Python爬虫进阶四之PySpider的用法

    审时度势 PySpider 是一个我个人认为非常方便并且功能强大的爬虫框架,支持多线程爬取.JS动态解析,提供了可操作界面.出错重试.定时爬取等等的功能,使用非常人性化. 本篇内容通过跟我做一个好玩的 ...

  7. 京东应用架构设计ppt阅读总结

    (一)架构设计原则总结: 1.架构愿景:高可用性.高可扩展性.低成本.多快好省(高时效.高人效.低成本) 2.业务架构设计原则:基础业务下沉抽象成平台.核心业务非核心业务分离.隔离不同类型的业务.主流 ...

  8. jquery的理解

    1.jquery的好处 简化js的复杂操作 不再需要关心兼容性 提供大量使用方法 2.jquery的设计思想 选择网页元素 -模拟css选择元素 -独有的表达式选择 -多种筛选方法 写法 -方法函数化 ...

  9. BCD码转换为十进制或者十进制转为BCD码

    BCD码其实就是之前在数字电路中说的 用4位二进制数值 来表示一个0-9中的数字,例如: 0000=0 0001=1 0010=2 0011=3也就是说如果把一个数字作为一个BCD码,例如: 11 2 ...

  10. checkbox数据回显问题

    一.问题 在用复选框的时候,最常用的无非就是全选,全不选,数据回显等问题!要做的比较灵活!最近做项目的时候,就遇到这些问题,下面从js和JQueyr两方面解决一下全选,全不选,数据回显的问题. 二.H ...