转载地址: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. ios 7.1企业证书无线安装

    ios升级到7.1时,企业证书http服务器发布无线安装不能使用,需要使用https服务器. 测试了几种方式 1.测试时自签名https证书测试无效,提示不能连接到服务器 2.使用dropbox共享连 ...

  2. 怎么给php下拉框默认选中

    比如说一个个人信息的编辑界面,从php界面传来了性别的值是0, 而html上有0 1 两个option 怎么能把0的那个option加上属性selected 用的是模板, 不要用原生的嵌在html中的 ...

  3. Spring boot——logback.xml 配置详解(四)<filter>

    阅读目录 1 filter的使用 2 常用的过滤器 文章转载自:http://aub.iteye.com/blog/1101260,在此对作者的辛苦表示感谢! 回到顶部 1 filter的使用 < ...

  4. Devexpress VCL Build v2013 vol 13.2.2 发布

    devexpress 2013 的第二个大版本出来了,一如既往, 基本上还是一个大补丁包.各位看官,自己看. What's New in 13.2.2 (VCL Product Line)   New ...

  5. 获取iPod library中的媒体文件

    [获取iPod library中的媒体文件] The Media Player framework provides facilities for playing movie, music, audi ...

  6. centos环境下创建数据库和表的方法

    centos环境下创建数据库和表的方法 //查询数据库的命令: mysql> SHOW DATABASES; +--------------------+ | Database         ...

  7. typedef char int8; 这样定义的好处?

    用typedef定义int8代表char:然后用int8去定义其他变量.一旦系统中char不再是占8位的数据时,可重新typedef新的占8位的类型为int8,而所有的用int8定义的8为类型数不用再 ...

  8. [label][responsive-web-design]网页响应测试各种尺寸的工具

    因为现在各种各样的尺寸上网设备 ,所以我们现在的网页设计都必须要兼容到各种尺寸的屏幕,必须测试各个 size下面的页面布局与排版. 一个开发人员是不可能拥有各种设备来进行测试,那么有没有什么便捷的工具 ...

  9. cxgrid的FINDPANEL编程

    cxgrid的FINDPANEL编程 FindPanel := TcxGridFindPanel.Create(cxGrid1DBTableView1.Controller); self.cxGrid ...

  10. IKAnalyzer兼容Lucene 5.4.0版本抛出异常?

    ava.lang.AbstractMethodError: org.apache.lucene.analysis.Analyzer.createComponents(Ljava/lang/String ...