Jetty实战之 嵌入式Jetty运行web app
转载地址:http://blog.csdn.net/kongxx/article/details/7237034
要说嵌入式运行Jetty,最常用的还应该是运行一个标准的war文件或者指定一个webapp目录。
0. 首先需要添加Jetty运行时webapp的依赖包,下面是一个完整的pom.xml文件
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"
- package com.google.code.garbagecan.jettystudy.sample6;
- import org.eclipse.jetty.server.Server;
- import org.eclipse.jetty.webapp.WebAppContext;
- public class WebAppContextWithWarServer {
- public static void main(String[] args) throws Exception {
- Server server = new Server(8080);
- WebAppContext context = new WebAppContext();
- context.setContextPath("/myapp");
- context.setWar("E:/share/test/struts2-blank.war");
- server.setHandler(context);
- server.start();
- server.join();
- }
- }
1.3 运行WebAppContextWithWarServer类,然后访问// http://localhost:8080/myapp/就可以看到struts2的例子界面了。
2. 运行一个webapp目录
2.1 还是用上面的struts2-blank.war,将这个war包解压后放到一个目录下;
2.2 创建自己的Jetty Server启动类WebAppContextWithFolderServer,其中指定了webapp目录,并指定context路径为"/myapp"
- package com.google.code.garbagecan.jettystudy.sample6;
- import org.eclipse.jetty.server.Server;
- import org.eclipse.jetty.webapp.WebAppContext;
- public class WebAppContextWithFolderServer {
- public static void main(String[] args) throws Exception {
- Server server = new Server(8080);
- WebAppContext context = new WebAppContext();
- context.setContextPath("/myapp");
- context.setDescriptor("E:/share/test/struts2-blank/WEB-INF/web.xml");
- context.setResourceBase("E:/share/test/struts2-blank");
- context.setParentLoaderPriority(true);
- server.setHandler(context);
- server.start();
- server.join();
- }
- }
2.3 运行WebAppContextWithFolderServer类,然后访问// http://localhost:8080/myapp/就可以看到struts2的例子界面了。
Jetty实战之 嵌入式Jetty运行web app的更多相关文章
- Jetty实战之 嵌入式Jetty运行Servlet
http://blog.csdn.net/kongxx/article/details/7230080 Jetty实战之 嵌入式Jetty运行Servlet 分类:JettyJava (19530) ...
- Jetty实战之 安装 运行 部署
本文地址:http://blog.csdn.net/kongxx/article/details/7218767 1. 首先从Jetty的官方网站http://wiki.eclipse.org/Jet ...
- (转)Jetty实战之 安装 运行 部署
http://blog.csdn.net/kongxx/article/details/7218767 本文地址:http://blog.csdn.NET/kongxx/article/details ...
- web项目嵌入Jetty运行的两种方式(Jetty插件和自制Jetty服务器)
在开发Java web项目时候,可以在项目中嵌入Jetty服务的方式来运行web程序. 由于最近开发web项目,自己使用的是比较旧的eclipse不支持导入tomcat来运行项目,于是就学习了下使用项 ...
- Jetty:部署到Jetty
Web应用的框架 标准Jetty公布版本号能部署标准servlet Spec Web应用和Jetty内部ContextHandler部署描写叙述符,或者两者的一个混合. Web应用是可部署的动态(se ...
- html5文章 -- 使用 jQuery Mobile 与 HTML5 开发 Web App ——开发原则 | Kayo's Melody
最近专注研究 jQuery Mobile —— 一款很方便就可以把 Web App 包装成适合 Android 与 iPhone 等触屏移动设备的 Javascript 库,结合 jQuery Mob ...
- Native APP ,Web APP,Hybrid APP三者对比
Native APP Native APP 指的是原生程序(Android.iOS.WP),一般依托于操作系统,有很强的交互,可拓展性强,需要用户下载安装使用,是一个完整的App. 原生应用程序是某一 ...
- 【Azure 应用服务】Azure Web App的服务(基于Windows 操作系统部署)在被安全漏洞扫描时发现了TCP timestamps漏洞
问题背景 什么是TCP timestamps(TCP 时间戳)? The remote host implements TCP Timestamps, as defined by RFC1323 (h ...
- 使用cmd命令创建maven(web)项目+项目转换成IDEA项目+项目打包+Jetty运行Web项目
3条件:配置好环境 配置环境教程:https://www.cnblogs.com/weibanggang/p/9623705.html 第一步:查看版本信息,在cmd输入mvn –version,如果 ...
随机推荐
- go 算法
题目: 请实现一个算法,确定一个字符串的所有字符[是否全都不同].这里我们要求[不允许使用额外的存储结构].给定一个string,请返回一个bool值,true代表所有字符全都不同,false代表存在 ...
- BloomFilter
[BloomFilter] 错误率估计.最优哗哈希函数个数.位数组的大小 尚未细看.以看补上. 参考:http://blog.csdn.net/jiaomeng/article/details/149 ...
- Volley的简单封装
算了一下,好像有很久没有写博客了.其实,关于写博客这件事,我从来没有把他当成我的一种任务,而是在学习过程中的一种总结和自我发现,同样也是为了练一练文笔,说不定有一天,我也能出一本书像<第一行代码 ...
- springmvc+mybaits一个事物同时update和调用存储过程异常回滚
事物作用的impl类这样写的 @Override public int updateReturnAll(int item, int status, int idUser) { // TODO Auto ...
- 解题报告-683. K Empty Slots
There is a garden with N slots. In each slot, there is a flower. The N flowers will bloom one by one ...
- python教学视频
3 X王的 链接: http://pan.baidu.com/s/1bW2UrO 密码: quit4 django 链接: http://pan.baidu.com/s/1o8UsNDS 密码: 8x ...
- eclipse两种注释的快捷键
方法一:使用Ctrl+/快捷键 1 第1步:在Eclipse中拖动鼠标,选中需要注释的代码,通常为连续多行代码. 2 第2步:按住Ctrl+/快捷键,如图所示. 3 第3步:会发现所选代码被“// ...
- windows server2012部署apache项目访问后台管理系统时tomcat就停了是怎么回事
是由于环境变量没有配好的原因,找不到jre目录 tomcat的运行需要JRE,一般启动闪退都是因为找不到JRE,也就是说环境安装JDK时环境变量没有配置好. 我们首先打开”命令提示符“窗口,输入jav ...
- GIT checkout 和 reset 区别
git checkout -- file:撤销对工作区修改:这个命令是以最新的存储时间节点(add和commit)为参照,覆盖工作区对应文件file:这个命令改变的是工作区 git reset HEA ...
- UVa 1615 Highway (贪心,区间选点问题)
题意:给定一个数 n 个点,和一个d,要求在x轴上选出尽量少的点,使得对于给定的每个点,都有一个选出的点离它的欧几里德距离不超过d. 析:首先这是一个贪心的题目,并且是区间选点问题,什么是区间选点呢, ...