Week 63 — What is the `jwebserver` tool?

Question of the Week #63
What is the jwebserver tool?
1 Reply
Eric McIntyre
Eric McIntyre9mo ago
Recent JDKs include a tool named jwebserver which is a simple HTTP server serving static files. It is possible to start it by entering the command jwebserver which then serves files in the current directory. By default, it uses port 8000 on the loopback interface (i.e. it only allows local connections). It is possible to change that behavior using command-line arguments. It's possible to change the address to listen to using -b, the directory to serve using -b and the port using -p. For example, the following command can be used to serve /tmp/someDirectory on all network interfaces using port 8080:
jwebserver -d /tmp/someDirectory -b 0.0.0.0 -p 8080
jwebserver -d /tmp/someDirectory -b 0.0.0.0 -p 8080
This tool is mainly for testing/getting an HTTP server for development. The JDK also provides an API for using it programmatically in the package com.sun.net.httpserver:
HttpServer server = SimpleFileServer.createFileServer(new InetSocketAddress(8080), Path.of("/tmp/someDirectory"), SimpleFileServer.OutputLevel.INFO);
server.start();
HttpServer server = SimpleFileServer.createFileServer(new InetSocketAddress(8080), Path.of("/tmp/someDirectory"), SimpleFileServer.OutputLevel.INFO);
server.start();
📖 Sample answer from dan1st
Want results from more Discord servers?
Add your server