使用嵌入式jetty实现文件服务器
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.nihaorz</groupId>
<artifactId>jetty-file-server</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.22.v20160922</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.nihaorz.app.AppStart</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
AppStart.java
package com.nihaorz.app; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.server.handler.ResourceHandler; import java.util.Properties; /**
* Created by Nihaorz on 2017/3/26.
*/
public class AppStart {
public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
Properties prop = new Properties();
prop.load(AppStart.class.getResourceAsStream("/config/jetty.properties"));
// 设置端口
Server server = new Server(Integer.parseInt(prop.getProperty("jetty.port")));
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(true);
// 设置本地磁盘路径
resourceHandler.setResourceBase(prop.getProperty("jetty.localPath"));
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{resourceHandler, new DefaultHandler()});
server.setHandler(handlers);
server.start();
long endTime = System.currentTimeMillis();
System.out.println("jetty正常启动,请访问 http://localhost:" + prop.getProperty("jetty.port"));
System.out.println("jetty服务启动耗时:" + (endTime - startTime) + "ms");
System.out.println("如需修改启动端口及本地映射路径请修改jar包中config目录下的jetty.properties");
}
}
jetty.properties
#jetty启动端口
jetty.port=9999
#映射路径
jetty.localPath=H:\
然后在工程根目录执行 mvn clean compile assembly:single,就会在工程target目录下生成jar文件
使用java -jar [jar文件路径]运行即可
我打包的jar文件下载地址
使用嵌入式jetty实现文件服务器的更多相关文章
- 嵌入式jetty的HTTP实现
2 嵌入式jetty的HTTP实现 布拉君君 2.1 简单HTTP实现 2.1.1 HTTP SERVER端实现 2.1.1.1 HTTP SERVER端实现概述 在代码中嵌入一个Jetty s ...
- Jetty实战之 嵌入式Jetty运行Servlet
http://blog.csdn.net/kongxx/article/details/7230080 Jetty实战之 嵌入式Jetty运行Servlet 分类:JettyJava (19530) ...
- Jetty实战之 嵌入式Jetty运行web app
Jetty实战之 嵌入式Jetty运行web app 博客分类: 应用服务器 jettywar 转载地址:http://blog.csdn.net/kongxx/article/details/72 ...
- Message高级特性 & 内嵌Jetty实现文件服务器
1. Messaage Properties 常见属性 更多的属性以及介绍参考:http://activemq.apache.org/activemq-message-properties.html ...
- 嵌入式jetty
一.maven依赖 pom配置 <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId&g ...
- Jetty 9嵌入式开发
官方网址:http://www.eclipse.org/jetty/ 下载地址:http://download.eclipse.org/jetty/stable-9/dist/ 文档网址:http:/ ...
- 一.配置简单的嵌入式tomcat和jetty
我们写了一个web应用,打成war包后,就需要找一个server来部署.对于我们的实际应用,我们基本没必要自己再写一个嵌入式的server.接下来两篇文章只是以钻研的心态来学习一下嵌入式tomcat和 ...
- 使用ActiveMQ 传输文件 以及使用Jetty搭建内嵌文件服务器
使用Active发送文件 ActiveMq 本身提供对于传输文件的支持. 1. 直接传输文件: 使用connection.createOutputStream 的形式.这种方式适合小文件.不能传输大文 ...
- Jetty使用教程(四:21-22)—Jetty开发指南
二十一.嵌入式开发 21.1 Jetty嵌入式开发HelloWorld 本章节将提供一些教程,通过Jetty API快速开发嵌入式代码 21.1.1 下载Jetty的jar包 Jetty目前已经把所有 ...
随机推荐
- Ubuntu 上安装QTAV第三方视频库
安装QtAV的基本环境: sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev sudo apt-get ...
- 《Google软件测试之道》简介
<Google软件测试之道>,一直听朋友讲起这本书,出于琐事太多,一直没机会拜读,最近部门架构觉得我们IT部门的技术太low,就给我们挑选了一些书籍,让我们多看看... 个人的一种学习习惯 ...
- SkylineGlobe SFS发布的WFS和WMS服务测试
SkylineGlobe SFS发布的WFS服务:http://localhost/SFS/streamer.ashx?service=wfs&request=GetCapabilities& ...
- 交换左Ctrl键和Caps lock键
Windows 10 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control ...
- python 取值方法:截取字符串
截取最后三位:aa=“TFR20171230001-1”cc=aa[-3]+aa[-2]+aa[-1] aa="1.36x36.8-ddr" bb=aa.split('x')[1] ...
- chrome浏览器直接打印 - z
在地址栏敲: about:flags ,打开设置界面:停用:Enable Print Preview Registration PromosChrome快捷方式增加:--kiosk-printing这 ...
- Webpack 2 视频教程 003 - Webpack 项目初始化
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- Centos下内网DNS主从环境部署记录
一.DNS是什么?DNS(Domain Name System),即域名系统.它使用层次结构的命名系统,将域名和IP地址相互映射,形成一个分布式数据库系统. DNS采用C-S架构,服务器端工作在UDP ...
- SpringMVC环境搭建——HelloWorld
1.新建Maven Web 工程: 2.添加相关的依赖包(Spring MVC.tomcat插件等),具体的pom.xml文件如下 <project xmlns="http://mav ...
- CF 1047 C. Enlarge GCD
传送门 [http://codeforces.com/contest/1047/problem/C] 题意 给你n个数,移除最少的数字使剩下的数字GCD大于初始GCD 思路 需要一点暴力的技巧,先求出 ...