Use the Build-In HTTP Server in Java 18
How to use the simple, build-in HTTP server which comes with Java 18 to serve static files
Java 18 ships in with a simple web server (JEP 408: Simple Web Server) which can serve static files.
To get Java 18, use the version provided by the Adoptium Project or Azul Zulu OpenJDK.
To start the server simply use the jwebserver command: This will start the server in the foreground bound to the port 8000. The port can be changed with the -p option:
$ jwebserver -p 4500
The server will serve files from the current directory (the directory can be changed with the -d option).
The server can be also started programmatically:
var servedPath = Paths
.get("/Users/devlabs-ninja")
.toAbsolutePath();
var address = new InetSocketAddress(9000);
var server = SimpleFileServer.createFileServer(
address,
servedPath,
OutputLevel.VERBOSE);
server.start();