Jetty实战之 嵌入式Jetty运行web app

博客分类:

  • 应用服务器
jettywar 

转载地址: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"

Java代码  
  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"

Java代码  
  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的例子界面了。

转载于:https://www.cnblogs.com/yangmengdx3/p/4744543.html

Jetty实战之 嵌入式Jetty运行web app相关推荐

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

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

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

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

  3. jetty 配置jndi_使用Jetty设置JNDI(嵌入式)

    jetty 配置jndi 我在开发工作区上运行嵌入式Jetty,从而节省了一些恶性的编译和部署周期. 我与Jetty的合作不多,易用性使我着迷于它. 我需要设置JNDI才能检索与数据库相关的活动的连接 ...

  4. webstorm配置环境变量_sulky环境配置,node.js安装以及如何运行webstorm的web app项目...

    该文章用来记笔记用的,主要记录如何在webstorm上运行一个app项目,希望对于需要的人有帮助. 首先,要运行web app项目,必须先装好相应的环境以及配置. 其中node.js和其他需要的配置在 ...

  5. 使用 jQuery Mobile 与 HTML5 开发 Web App (一) ——开发原则

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

  6. jetty服务器上运行html页面,web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)...

    自制Jetty服务类 这种方式可以支持websocket,如果项目中需要使用到可以试试这种. 首先pom.xml引入jetty的依赖: org.eclipse.jetty.aggregate jett ...

  7. Eclipse下通过Maven的Jetty插件运行Web工程的配置,包括启动https

    摘要: 之前写了Eclipse下怎么通过 Maven 的 Tomcat 插件来运行 Web 工程.近日听说 Jetty 可以动态加载修改后的类, 为了能够更快提高开发效率, 绝对要尝试一下. 引用来源 ...

  8. jetty 通过配置文件嵌入式启动web服务

    定义 jetty.xml 启动文件 <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty ...

  9. 嵌入式jetty的HTTP实现

    http://www.cnblogs.com/zzt-lovelinlin/p/5275168.html 2.1 简单HTTP实现 2.1.1 HTTP SERVER端实现 2.1.1.1 HTTP ...

最新文章

  1. 配置隧道模式的IPSec.×××
  2. iMeta | 南科大宋毅组综述逆境胁迫下植物向微生物组求救的遗传基础(附招聘)
  3. nvidia-smi 实时刷新 实时显示显存使用情况
  4. 【推荐系统】KDD2021推荐系统论文集锦
  5. JVM 调优实战--垃圾回收的常见算法
  6. 一天干掉一只Monkey计划(二)——热流扰动,径向模糊
  7. [postgresql] postgresql 安装
  8. qq远程控制电脑方法_【技术分享】教你远程控制别人电脑
  9. [Java基础]生产者和消费者模式概述与案例分析
  10. 牛客 21302 被3整除的子序列 (动态规划、Python)
  11. 安装插件设置Intellij IDEA背景图片
  12. 申请成功Azure帐号开始学习Azure云计算
  13. ThinkPHP视图模型实例
  14. WDM驱动开发 电源管理
  15. 在Mac下载安装win10虚拟机教程及分辨率等问题。
  16. html改变元素外边距,CSS 简明教程 - 外边距 ( margin ) 属性
  17. 正负用c语言表示,用C表示负数?
  18. 该卸载PhotoShop了!MIT用AI实现3分钟自动抠图,精细到头发丝
  19. CF1579E1 Permutation Minimization by Deque
  20. Android性能优化(二)—— 内存优化

热门文章

  1. 机房收费系统重构之存储过程的使用
  2. ListView详解 (ListView图文混排)
  3. Enterprise Architect
  4. 贪心算法--多处最优服务次序问题
  5. svn: E200009
  6. Makefile_01:什么是Makefile?
  7. 支付宝和微信的支付流程图
  8. 在switch case 语句中能否使用continue 关键字?为什么?
  9. spring18-3: 工厂bean代理-半自动
  10. 运算方法和运算部件一