It is recommended that you configure your web server with an environment variable. Following the next code example will help you to confirm if it is in production or local.
// You could use this in your scenario with your own variable.
// PORT environment variable when present, otherwise on 8080.
int port = Integer.parseInt(System.getenv().getOrDefault("PORT", "8080"));
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0);
But also, reviewing this GitHub repository, you can actually use your current code in Java 8 for Java 11.