使用嵌入式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目前已经把所有 ...
随机推荐
- Android学习之基础知识八—Android广播机制
一.广播机制简介 Android提供了一套完整的API,允许应用程序自由的发送和接受广播,发送广播借助于我们之前学过的:Intent,而接收广播需要借助于广播接收器(Broadcast Receive ...
- python:利用smtplib模块发送邮件
自动化测试中,测试报告一般都需要发送给相关的人员,比较有效的一个方法是每次执行完测试用例后,将测试报告(HTML.截图.附件)通过邮件方式发送. 参考代码:send_mail.py 一.python对 ...
- MySQL(十四)管理维护及性能优化
关于MySQL的学习,<MySQL必知必会>这本书呢,看完已经两个月了,一直被工作以及生活的一些琐事拖着,趁着今晚有空闲,就整理完了最后的几章学习笔记,接下来的学习计划呢, 应该是pyth ...
- 如何构造分层次的 Json 数据
十年河东,十年河西,莫欺骚年穷...打错个字~_~ 现有如下需求,构造分层次的Json数据,层次结构类似下图: 上图使用EasyUI生成的,静态HTML如下: <html xmlns=" ...
- linux的convert图片处理工具
得到一个图片的尺寸, identify test.png 结果为: test.png PNG 178x15 178x15+0+0 16-bit PseudoClass 65536c 2.28kb 使用 ...
- git push上传代码到gitlab上,报错401/403(或需要输入用户名和密码)
之前部署的gitlab,采用ssh方式连接gitlab,在客户机上产生公钥上传到gitlab的SSH-Keys里,git clone下载和git push上传都没问题,这种方式很安全. 后来应开发同事 ...
- C_数据结构_数组
//数组 # include <stdio.h> # include <malloc.h> //包含了 malloc 函数 # include <stdlib.h> ...
- Ubuntu14.04安装PyMuPDF
最近写的一个东西需要将pdf转成图片然后放在网页上展示,找到了个非常好用的轮子叫做PyMuPDF,在windows上测试的时候跑的666,在ubuntu上安装依赖的时候,简直万脸懵逼.github上给 ...
- Week3 关于“微软必应词典客户端”的案例分析
第一部分 调研,评测 一.iphone客户端的bug挖掘: 1.在例句中点击单词或短语,如果这个时候点得稍微快了一点,关联相应的翻译时会出现混乱. 经过调查发现,这个bug应该是必应得一个全平台错误 ...
- Android 學習之旅!(2)
早幾天因爲學車,弄了幾天時間和精力過去,今天終於考過了(科目二,還是補考的...)嗯..不管這麼多了..今天又開始我的android 學習之旅!! 筆記: platform-tools目錄下的文件: ...