当我" mvn exec:java" java程序时,我有问题将端口设置为80,但是8080可以成功。
Undertow server = Undertow.builder()
.addHttpListener(80, "localhost")
.setHandler(path)
.build();
server.start();
当我将其设置为80时,我得到了
之类的例外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
您需要root访问才能能够在1024以下的所有端口上收听。以root或sudo
命令启动您的应用程序。