3

Java 18 新特性:使用Java代码启动jwebserver

 2 years ago
source link: https://blog.didispace.com/java18-jep408-jwebserver-2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Java 18 新特性:使用Java代码启动jwebserver

昨天分享了Java 18 新特性:简单Web服务器的jwebserver命令行功能。今天换一种方式,使用Java代码来实现一个静态资源服务器。

详细步骤我录了个视频放到B站了,感兴趣的小伙伴可以点击查看Java 18 新特性:Simple Web Server(2)

代码比较简单,直接贴出来了:

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");

var addr = new InetSocketAddress(9000);
var server = SimpleFileServer.createFileServer(
addr, Path.of("/"), SimpleFileServer.OutputLevel.INFO);
server.start();
}
}

巩固一下上一篇jwebserver的内容,根据上面的代码,如果用jwebserver来实现,实际上就是下面的命令:

jwebserver -p 9000 -d / -o info

看看你的理解对不对吧!好了,今天的分享就到这里!如果您学习过程中如遇困难?可以加入我们超高质量的技术交流群,参与交流与讨论,更好的学习与进步!另外,不要走开,关注我!持续更新Java新特性教程!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK