JWEBSERVER
Section: JDK Commands (1)
Updated: 2023
Index
Return to Main Contents
NAME
jwebserver- launch the Java Simple Web Server
SYNOPSIS
V]jwebserverR] [I]optionsR]]
- I]optionsR]
-
Comman-line options.
For a detailed description of the options, see B]OptionsR].
DESCRIPTION
The V]jwebserverR] 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.
Only idempotent HEAD and GET requests are served.
Any other requests receive a V]501- Not ImplementedR] or a
V]405- Not AllowedR] response.
GET requests are mapped to the directory being served, as follows:
- [bu]
-
If the requested resource is a file, its content is served.
- [bu]
-
If the requested resource is a directory that contains an index file,
the content of the index file is served.
- [bu]
-
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 buil-in table.
For example, V].htmlR] files are served as V]text/htmlR] and
V].javaR] files are served as V]text/plainR].
V]jwebserverR] is located in the jdk.httpserver module, and can
alternatively be started with V]java-m jdk.httpserverR].
It is based on the web server implementation in the
V]com.sun.net.httpserverR] package.
The V]com.sun.net.httpserver.SimpleFileServerR] class provides a
programmatic way to retrieve the server and its components for reuse and
extension.
USAGE
-
CB]
jwebserver -b bind address] -p port] -d directory]
-o none|info|verbose] -h to show options]
-version to show version information]
R]
OPTIONS
- V-hR] or V-?R] or V-helpR]
-
Prints the help message and exits.
- V-bR] I]addrR] or V-bin-addressR] I]addrR]
-
Specifies the address to bind to.
Default: 127.0.0.1 or ::1 (loopback).
For all interfaces use V-b 0.0.0.0R] or V-b ::R].
- V-dR] I]dirR] or V-directoryR] I]dirR]
-
Specifies the directory to serve.
Default: current directory.
- V-oR] I]levelR] or V-outputR] I]levelR]
-
Specifies the output format.
V]noneR] | V]infoR] | V]verboseR].
Default: V]infoR].
- V-pR] I]portR] or V-portR] I]portR]
-
Specifies the port to listen on.
Default: 8000.
- V-versionR] or V-versionR]
-
Prints the version information and exits.
To stop the server, press V]Ctrl + CR].
STARTING THE SERVER
The following command starts the Simple Web Server:
-
CB]
$ jwebserver
R]
If startup is successful, the server prints a message to
V]System.outR] listing the local address and the absolute path of
the directory being served.
For example:
-
CB]
$ jwebserver
Binding to loopback by default. For all interfaces use [dq-b 0.0.0.0[dq] or [dq-b ::[dq].
Serving /cwd and subdirectories on 127.0.0.1 port 8000
URL http://127.0.0.1:8000/
R]
CONFIGURATION
By default, the server runs in the foreground and binds to the loopback
address and port 8000.
This can be changed with the V-bR] and V-pR] options.
For example, to bind the Simple Web Server to all interfaces, use:
-
CB]
$ 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/
R]
Note that this makes the web server accessible to all hosts on the
network.
I]Do not do this unless you are sure the server cannot leak any
sensitive information.R]
As another example, use the following command to run on port 9000:
-
CB]
$ jwebserver-p 9000
R]
By default, the files of the current directory are served.
A different directory can be specified with the V-dR] option.
By default, every request is logged on the console.
The output looks like this:
-
CB]
127.0.0.1-- [10/Feb/2021:14:34:11 +0000] [dq]GET /some/subdirectory/ HTTP/1.1[dq] 200-
R]
Logging output can be changed with the V-oR] option.
The default setting is V]infoR].
The V]verboseR] 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
V]SIGINTR] signal (V]Ctrl+CR] in a terminal window).
HELP OPTION
The V-hR] option displays a help message describing the usage and
the options of the V]jwebserverR].
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- USAGE
-
- OPTIONS
-
- STARTING THE SERVER
-
- CONFIGURATION
-
- STOPPING THE SERVER
-
- HELP OPTION
-