When I "mvn exec:java" the java program, I have problems to set port to 80, but 8080 can be successful.
Undertow server = Undertow.builder()
.addHttpListener(80, "localhost")
.setHandler(path)
.build();
server.start();
when I set it as 80, i got exceptions like
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.net.SocketException: Permission denied
at io.undertow.Undertow.start(Undertow.java:141)
at cc.cmu.edu.Q1.Q1Controller.main(Q1Controller.java:46)
... 6 more
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67)
at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:175)
at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:242)
at io.undertow.Undertow.start(Undertow.java:120)
... 7 more
You need root access to be able to listen on all ports below 1024.
Start your application as root, or with a sudo
command.