参考地址:http://undertow.io/undertow-docs/undertow-docs-1.3.0/index.html
1、引入相关jar
<dependencies> <dependency> <groupId>io.undertow</groupId> <artifactId>undertow-core</artifactId> <version>2.0.22.Final</version> </dependency> </dependencies>
2、编写启动函数
package com.msj; import io.undertow.Handlers; import io.undertow.Undertow; import io.undertow.server.handlers.resource.PathResourceManager; import java.io.File; /** * @author 苗士军 * @version 1.0 * @date 2019/9/25 */ public class UndertowServer { public static void main(String[] args) { File file = new File("D:/undertow"); Undertow server = Undertow.builder().addHttpListener(1234, "localhost") .setHandler(Handlers.resource(new PathResourceManager(file.toPath(), 100)) .setDirectoryListingEnabled(true)) .build(); server.start(); } }
3、启动main函数,浏览器输入地址,可以看到相关文件