JWEBSERVER(1)

πŸ“¦ version 22.0.2.0, in opensuse-leap 16.0

πŸ’… JWEBSERVER β€” launch the Java Simple Web Server

okay bestie, so this is the jwebserver page from the JDK Commands manual, and it's genuinely one of the cutest little tools in the whole JDK. it's a baby HTTP server. it serves files. it does not do drama. let's get into it πŸŽ€


✨ NAME ✨

jwebserver β€” launch the Java Simple Web Server πŸ¦‹


🌸 SYNOPSIS 🌸

jwebserver [options]

options β€” the command-line options, obviously πŸ’… and if you want the full tea on each one, scroll down to Options.


🫢 DESCRIPTION 🫢

so jwebserver gives you a minimal HTTP server, and it was literally made for prototyping, testing, and debugging. that's the vibe. it serves a single directory hierarchy, and only serves static files. no cap.

Only HTTP/1.1 is supported. HTTP/2 and HTTPS are not supported β€” so don't come looking for a padlock icon, it's not that kind of party 😭

Only idempotent HEAD and GET requests get served. Any other request gets a 501 - Not Implemented or a 405 - Not Allowed response. periodt. GET requests are mapped to the directory being served like this:

  • If the requested resource is a file, its content is served. πŸ“
  • If the requested resource is a directory that contains an index file, the content of the index file is served.
  • Otherwise, the names of all files and subdirectories of the directory are listed. Symbolic links and hidden files are not listed or served. πŸ™ˆ (they're lowkey in witness protection)

MIME types are configured automatically using the built-in table. for example, .html files are served as text/html and .java files are served as text/plain. it just knows. iykyk ✨

jwebserver is located in the jdk.httpserver module, and can alternatively be started with java -m jdk.httpserver. It is based on the web server implementation in the com.sun.net.httpserver package. And the com.sun.net.httpserver.SimpleFileServer class provides a programmatic way to retrieve the server and its components for reuse and extension β€” so yes you can absolutely take it apart and rebuild it, main character energy πŸ‘‘


🌈 USAGE 🌈

jwebserver [-b bind address] [-p port] [-d directory]
           [-o none|info|verbose] [-h to show options]
           [-version to show version information]

πŸ’– OPTIONS πŸ’–

  • -h or -? or --help β€” prints the help message and exits. cute, quick, done πŸ’…
  • -b addr or --bind-address addr β€” specifies the address to bind to. Default: 127.0.0.1 or ::1 (loopback). For all interfaces use -b 0.0.0.0 or -b ::. πŸ¦‹
  • -d dir or --directory dir β€” specifies the directory to serve. Default: current directory.
  • -o level or --output level β€” specifies the output format. none | info | verbose. Default: info.
  • -p port or --port port β€” specifies the port to listen on. Default: 8000.
  • -version or --version β€” prints the version information and exits. ⭐

To stop the server, press Ctrl + C. 🫢


πŸŽ€ STARTING THE SERVER πŸŽ€

the following command starts the Simple Web Server:

$ jwebserver

If startup is successful, the server prints a message to System.out listing the local address and the absolute path of the directory being served. For example:

$ jwebserver
Binding to loopback by default. For all interfaces use "-b 0.0.0.0" or "-b ::".
Serving /cwd and subdirectories on 127.0.0.1 port 8000
URL http://127.0.0.1:8000/

look at it go 😭✨


🧚 CONFIGURATION 🧚

By default, the server runs in the foreground and binds to the loopback address and port 8000. This can be changed with the -b and -p options. For example, to bind the Simple Web Server to all interfaces, use:

$ jwebserver -b 0.0.0.0
Serving /cwd and subdirectories on 0.0.0.0 (all interfaces) port 8000
URL http://123.456.7.891:8000/
⚠️ note that this makes the web server accessible to all hosts on the network. Do not do this unless you are sure the server cannot leak any sensitive information. fr fr, do not be out here exposing your whole filesystem because it seemed fun πŸ’€

As another example, use the following command to run on port 9000:

$ jwebserver -p 9000

By default, the files of the current directory are served. A different directory can be specified with the -d option.

By default, every request is logged on the console. The output looks like this:

127.0.0.1 - - [10/Feb/2021:14:34:11 +0000] "GET /some/subdirectory/ HTTP/1.1" 200 -

Logging output can be changed with the -o option. The default setting is info. The verbose setting additionally includes the request and response headers as well as the absolute path of the requested resource. it's giving receipts πŸ‘‘


πŸ”₯ STOPPING THE SERVER πŸ”₯

Once started successfully, the server runs until it is stopped. On Unix platforms, the server can be stopped by sending it a SIGINT signal (Ctrl+C in a terminal window). bye bestie πŸ’œ


πŸ’€ HELP OPTION πŸ’€

The -h option displays a help message describing the usage and the options of the jwebserver. when in doubt, -h it out 🌸


and that's the whole page, bestie πŸŽ€βœ¨ this was the JWEBSERVER(1) page from the JDK 22 docs, dated 2024 β€” go forth and serve some static files, you iconic little sysadmin πŸ«ΆπŸ’–

πŸ“¦ where this page comes from