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,如果 ...
随机推荐
- mac下搭建appium
1.安装java 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html ...
- Android 建立Menu选单&&onOptionsItemSelected (转)
/** 当Menu有命令被选择时,会调用此方法 */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (i ...
- 22.Generate Parentheses (String; Back-Track)
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- Spring IoC入门
------------------siwuxie095 Spring IoC 环境搭建 1.先下载相关库文件,下载链接 ...
- oracle忘记密码,修改密码
1:输入命令: sqlplus /nolog ,进入oracle控制台,并输入 conn /as sysdba;以DBA角色进入.2:若修改某一个用户密码, 修改用户口令 格式为:alter user ...
- mongon命令(转)
原文:http://www.cnblogs.com/blueness-sunshine/p/6139092.html 连接mongodb: mongo -u --authenticationDat ...
- eclipse中maven install提示编码GBK的不可映射字符
今天在eclipse中使用Maven编译项目源代码时,结果如下了如下的错误 在Java源码中没有提示任何报错,即便是改掉项目编码也是不行,如下图所示:
- (最小生成树)Eddy's picture -- hdu -- 1162
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1162 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- apache mpm的一些问题
win2003系统下apache环境,mpm_winnt.c模式,优化参数: ThreadsPerChild 说明:每个子进程建立的线程数,默认值:64,最大值:1920.网上查询资料建议设置在100 ...
- 执行计划--WHERE条件的先后顺序对执行计划的影响
在编写SQL时,会建议将选择性高(过滤数据多)的条件放到WHERE条件的前面,这是为了让查询优化器优先考虑这些条件,减少生成最优(或相对最优)的执行计划的时间,但最终的执行计划生成过滤顺序还是决定这些 ...