.\" Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. .\" DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. .\" .\" This code is free software; you can redistribute it and/or modify it .\" under the terms of the GNU General Public License version 2 only, as .\" published by the Free Software Foundation. .\" .\" This code is distributed in the hope that it will be useful, but WITHOUT .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License .\" version 2 for more details (a copy is included in the LICENSE file that .\" accompanied this code). .\" .\" You should have received a copy of the GNU General Public License version .\" 2 along with this work; if not, write to the Free Software Foundation, .\" Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. .\" .\" Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA .\" or visit www.oracle.com if you need additional information or have any .\" questions. .\" .\" Automatically generated by Pandoc 2.3.1 .\" .TH "JWEBSERVER" "1" "2022" "JDK 19" "JDK Commands" .hy .SH NAME .PP jwebserver \- launch the Java Simple Web Server .SH SYNOPSIS .PP \f[CB]jwebserver\f[R] [\f[I]options\f[R]] .TP .B \f[I]options\f[R] Command\-line options. For a detailed description of the options, see \f[B]Options\f[R]. .RS .RE .SH DESCRIPTION .PP The \f[CB]jwebserver\f[R] 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. .PP Only idempotent HEAD and GET requests are served. Any other requests receive a \f[CB]501\ \-\ Not\ Implemented\f[R] or a \f[CB]405\ \-\ Not\ Allowed\f[R] response. GET requests are mapped to the directory being served, as follows: .IP \[bu] 2 If the requested resource is a file, its content is served. .IP \[bu] 2 If the requested resource is a directory that contains an index file, the content of the index file is served. .IP \[bu] 2 Otherwise, the names of all files and subdirectories of the directory are listed. Symbolic links and hidden files are not listed or served. .PP MIME types are configured automatically, using the built\-in table. For example, \f[CB]\&.html\f[R] files are served as \f[CB]text/html\f[R] and \f[CB]\&.java\f[R] files are served as \f[CB]text/plain\f[R]. .PP \f[CB]jwebserver\f[R] is located in the jdk.httpserver module, and can alternatively be started with \f[CB]java\ \-m\ jdk.httpserver\f[R]. It is based on the web server implementation in the \f[CB]com.sun.net.httpserver\f[R] package. The \f[CB]com.sun.net.httpserver.SimpleFileServer\f[R] class provides a programmatic way to retrieve the server and its components for reuse and extension. .SH USAGE .IP .nf \f[CB] jwebserver\ [\-b\ bind\ address]\ [\-p\ port]\ [\-d\ directory] \ \ \ \ \ \ \ \ \ \ \ [\-o\ none|info|verbose]\ [\-h\ to\ show\ options] \ \ \ \ \ \ \ \ \ \ \ [\-version\ to\ show\ version\ information] \f[R] .fi .SH OPTIONS .TP .B \f[CB]\-h\f[R] or \f[CB]\-?\f[R] or \f[CB]\-\-help\f[R] Prints the help message and exits. .RS .RE .TP .B \f[CB]\-b\f[R] \f[I]addr\f[R] or \f[CB]\-\-bind\-address\f[R] \f[I]addr\f[R] Specifies the address to bind to. Default: 127.0.0.1 or ::1 (loopback). For all interfaces use \f[CB]\-b\ 0.0.0.0\f[R] or \f[CB]\-b\ ::\f[R]. .RS .RE .TP .B \f[CB]\-d\f[R] \f[I]dir\f[R] or \f[CB]\-\-directory\f[R] \f[I]dir\f[R] Specifies the directory to serve. Default: current directory. .RS .RE .TP .B \f[CB]\-o\f[R] \f[I]level\f[R] or \f[CB]\-\-output\f[R] \f[I]level\f[R] Specifies the output format. \f[CB]none\f[R] | \f[CB]info\f[R] | \f[CB]verbose\f[R]. Default: \f[CB]info\f[R]. .RS .RE .TP .B \f[CB]\-p\f[R] \f[I]port\f[R] or \f[CB]\-\-port\f[R] \f[I]port\f[R] Specifies the port to listen on. Default: 8000. .RS .RE .TP .B \f[CB]\-version\f[R] or \f[CB]\-\-version\f[R] Prints the version information and exits. .RS .RE .PP To stop the server, press \f[CB]Ctrl\ +\ C\f[R]. .SH STARTING THE SERVER .PP The following command starts the Simple Web Server: .IP .nf \f[CB] $\ jwebserver \f[R] .fi .PP If startup is successful, the server prints a message to \f[CB]System.out\f[R] listing the local address and the absolute path of the directory being served. For example: .IP .nf \f[CB] $\ 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/ \f[R] .fi .SH CONFIGURATION .PP By default, the server runs in the foreground and binds to the loopback address and port 8000. This can be changed with the \f[CB]\-b\f[R] and \f[CB]\-p\f[R] options. .PD 0 .P .PD For example, to bind the Simple Web Server to all interfaces, use: .IP .nf \f[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/ \f[R] .fi .PP Note that this makes the web server accessible to all hosts on the network. \f[I]Do not do this unless you are sure the server cannot leak any sensitive information.\f[R] .PP As another example, use the following command to run on port 9000: .IP .nf \f[CB] $\ jwebserver\ \-p\ 9000 \f[R] .fi .PP By default, the files of the current directory are served. A different directory can be specified with the \f[CB]\-d\f[R] option. .PP By default, every request is logged on the console. The output looks like this: .IP .nf \f[CB] 127.0.0.1\ \-\ \-\ [10/Feb/2021:14:34:11\ +0000]\ "GET\ /some/subdirectory/\ HTTP/1.1"\ 200\ \- \f[R] .fi .PP Logging output can be changed with the \f[CB]\-o\f[R] option. The default setting is \f[CB]info\f[R]. The \f[CB]verbose\f[R] setting additionally includes the request and response headers as well as the absolute path of the requested resource. .SH STOPPING THE SERVER .PP Once started successfully, the server runs until it is stopped. On Unix platforms, the server can be stopped by sending it a \f[CB]SIGINT\f[R] signal (\f[CB]Ctrl+C\f[R] in a terminal window). .SH HELP OPTION .PP The \f[CB]\-h\f[R] option displays a help message describing the usage and the options of the \f[CB]jwebserver\f[R].