JWEBSERVER(1)
π NAME π
Okay bestie, meet jwebserver β the launch button for the Java Simple Web Server. This page is jwebserver(1) β yes, the JWEBSERVER(1) one β and it lives in the JDK Commands family. Slay. π
β¨ SYNOPSIS β¨
Hereβs the whole vibe:
jwebserver [options]
options β Command-line options. For a detailed description of the options, see Options. π«Ά
π DESCRIPTION π
The jwebserver tool provides a minimal HTTP server, designed to be used for prototyping, testing, and debugging. It serves a single directory hierarchy, and only serves static files. Only HTTP/1.1 is supported; HTTP/2 and HTTPS are not supported. No cap. β¨
Only idempotent HEAD and GET requests are served. Any other requests receive a 501 - Not Implemented or a 405 - Not Allowed response. Periodt. π
GET requests are mapped to the directory being served, as follows:
- 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. π
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. π
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. The com.sun.net.httpserver.SimpleFileServer class provides a programmatic way to retrieve the server and its components for reuse and extension. π
β USAGE β
jwebserver [-b bind address] [-p port] [-d directory]
[-o none|info|verbose] [-h to show options]
[-version to show version information]
π OPTIONS π
-hor-?or--helpβ Prints the help message and exits. π-b addror--bind-address addrβ Specifies the address to bind to. Default:127.0.0.1or::1(loopback). For all interfaces use-b 0.0.0.0or-b ::. π-d diror--directory dirβ Specifies the directory to serve. Default: current directory. π-o levelor--output levelβ Specifies the output format.none|info|verbose. Default:info. π-p portor--port portβ Specifies the port to listen on. Default:8000. π-versionor--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/
βοΈ 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. Thatβs a serious yikes if you skip it. π
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. π
π 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). π
π HELP OPTION π
The -h option displays a help message describing the usage and the options of the jwebserver. π«Ά
And thatβs the whole jwebserver(1) tea. This page is from JDK 21, dated 2023, and itβs giving JWEBSERVER(1) energy all the way to the end. Bye bestie, go serve some static files responsibly. ππ
π¦ where this page comes from
- opensuse-leap 16.0: java-21-openj9-devel 21.0.11.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-21-openj9-devel 21.0.11.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-21-openj9-devel 21.0.11.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- opensuse-leap 16.0: java-21-openj9-devel 21.0.11.0-bp160.1.1 Β· Apache-1.1 AND Apache-2.0 AND EPL-2.0 AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-only WITH Classpath-exception-2.0 AND LGPL-2.0-only AND MPL-1.0 AND MPL-1.1 AND LicenseRef-SUSE-Public-Domain AND W3C
- Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms