java jetty的classpath_java代码启动jetty
记录下
org.eclipse.jetty
jetty-server
${jetty.version}
test
org.eclipse.jetty
jetty-webapp
${jetty.version}
test
public class MonitorJetty {
/** port */
private int port = 8090;
protected String charset = "UTF-8";
public MonitorJetty() {
}
public MonitorJetty(int port) {
this.port = port;
}
public MonitorJetty(int port, String charset) {
super();
this.port = port;
this.charset = charset;
}
/**
* 服务器启动。
*
*/
public void start() {
// 设置Jetty日志
System.setProperty("org.eclipse.jetty.util.log.class", StdErrLog.class.getName());
HandlerCollection handlers = new HandlerCollection();
Server server = new Server(this.port);
RequestLogHandler requestLogHandler = new RequestLogHandler();
// 设置context
WebAppContext context = new WebAppContext();
context.setContextPath("/");
//这个地址的加载方式,eclipse和idea目录有区别,跟maven导入有关
//context.setResourceBase("./src/main/webapp");
//context.setDefaultsDescriptor("/src/test/java/jetty/webdefault.xml");
context.setResourceBase("./monitor/web/war/src/main/webapp");
context.setDefaultsDescriptor("monitor/web/war/src/test/java/jetty/webdefault.xml");
// PS:嵌入式的Jetty,应用当前工程的ClassPath,如果不设置将使用WebAppClassLoder,WEB-INF/lib目录加载jar。
context.setClassLoader(Thread.currentThread().getContextClassLoader());
context.setParentLoaderPriority(true);
handlers.setHandlers(new Handler[] { context, new DefaultHandler(), requestLogHandler });
server.setHandler(handlers);
// 启动Server
try {
server.start();
server.join();
} catch (Exception e) {
}
}
public static void main(String[] args) {
MonitorJetty server = new MonitorJetty();
server.start();
}
}
支持servlet3.0注解启动
http://www.eclipse.org/jetty/documentation/current/using-annotations-embedded.html
添加依赖
org.eclipse.jetty
jetty-annotations
9.3.17.RC0
org.eclipse.jetty
jetty-plus
9.3.17.RC0
org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
java jetty的classpath_java代码启动jetty相关推荐
- idea下,Jetty采用main方法启动web项目
为什么80%的码农都做不了架构师?>>> 对于maven多模块的spring web项目,本地开发时,启动的方式一般有如下几种: 使用容器(tomcat/jetty/resin ...
- jetty 通过配置文件嵌入式启动web服务
定义 jetty.xml 启动文件 <?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty ...
- Linux下jetty报java.lang.OutOfMemoryError: PermGen space及Jetty内存配置调优解决方案
Linux下的jetty报java.lang.OutOfMemoryError: PermGen space及Jetty内存配置调优解决方案 问题 linux的jetty下发布程序后再启动jetty服 ...
- linux java.net.bind,False java.net.BindException:已在Jetty上使用的地...
在我的CI服务器上,我有一个需要启动Jetty服务器的测试. 测试如下: >生成随机端口(在合法TCP端口范围内使用java rand). >使用Linux的热熔器进行验证以检查未使用的端 ...
- java代码启动电脑上程序方法
java代码启动电脑上程序 举个例子:打开电脑上的计算器 public static void main(String[] args) {try {Runtime.getRuntime().exec( ...
- java jetty eclipse_用Eclipse+Maven+Jetty构建Java Web开发环境(详细笔记)
(软件环境) 『系统』Windows 10 x64 『JAVA』JDK 1.8.0_91 『Eclipse』 Eclipse-oxygen 『Maven』 apache-maven-3.6.3 『Je ...
- Java——通过Java代码启动批处理文件(一)
作者专注于Java.架构.Linux.小程序.爬虫.自动化等技术. 工作期间含泪整理出一些资料,微信搜索[javaUp],回复 [java][黑客][爬虫][小程序][面试]等关键字免费获取资料.技术 ...
- Java——通过Java代码启动批处理文件(二)
前言 兄弟篇:Java--通过Java代码启动批处理文件(一) 第一篇是直接执行批处理文件,但是有两种情况不能处理: 1.路径里面带有空格的情况,2.环境变量设置问题The CATALINA_HOME ...
- linux查看jetty安装目录,linux中Jetty的安装和配置方法
Jetty Jetty 是一个开源的servlet容器,它为基于Java的web内容,例如JSP和servlet提供运行环境.Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布.开 ...
最新文章
- Numpy 从数值范围创建数组
- android 数字证书具体应用机制
- VMware vSphere/vCenter/ESX(i)介绍
- 已锁定计算机,计算机锁定怎么解除_计算机已锁定如何解除
- LeetCode 954. 二倍数对数组(map计数)
- python创建百万个文件_python百万sitemap制作
- 大家为什么去国企后都不想跳槽了?
- Spark集群试运行
- Chrome开发者工具插件
- 此数据库处于单用户模式,删除是提示,当前某个用户已与其连接。 ALTER DATABASE 语句失败。 (Microsoft SQL Server,错误: 5064)
- Windows - 强力删除文件
- 哈夫曼码的编译码系统
- Python语言为何如此流行?
- 本周最新文献速递20211121
- 《MLB棒球创造营》:走近棒球运动·奥克兰运动家队
- DateCalander
- java秃顶_【本人秃顶程序员】在Java中使用函数范式提高代码质量
- 学习人工智能可以从事哪些职业,有哪些就业前景和薪资待遇?
- Finance Overview
- [Unity]读取本地图片ArgumentException: A null reference or invalid value was found错误