Search code examples
web-serviceswebserverjava-9

Official web-server in Java 9


I need to build a simple HTTP server in Java using only the standard Java API. I found this question: simple HTTP server in Java using only Java SE API which has two answers that use only the standard Java API:

  • One answer is to use the com.sun.net.httpserver package, but this package is not an official part of Java.
  • Another answer is to use the javax.xml.ws package, but, according to the Java 9 documentation, this package is deprecated since Java 9.

So, what is the current official way to create a web-server?


Solution

  • The simple server, found in com.sun.net.httpserver is an official, but optional API in Java 9, located in the module jdk.httpserver. This implies that you can expect it to be maintained in OpenJDK, but not to be available in every JRE.

    If you can live with these conditions, you can use it.