Linux下jetty启动报错解决方法
源码:package com.svse.jetty;import org.mortbay.jetty.Connector;import org.mortbay.jetty.Server;import org.mortbay.jetty.nio.SelectChannelConnector;import org.mortbay.jetty.webapp.WebAppConte
源码:
package com.svse.jetty;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
public class JettyStarter {
public static void main(String args[]) throws Exception{
long begin = System.currentTimeMillis();
Connector connector = new SelectChannelConnector();
connector.setPort(Integer.getInteger("jetty.port",80).intValue());
WebAppContext webapp = new WebAppContext("WebRoot","/struts2");
Server server = new Server();
server.setConnectors(new Connector[]{connector});
server.setHandler(webapp);
server.start();
System.out.println("Jetty server started ,use " + (System.currentTimeMillis()-begin)+"ms");
}
}
报错:
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.Server.doStart(Server.java:233)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.svse.jetty.JettyStarter.main(JettyStarter.java:20)
2014-03-09 11:59:28.082::WARN: failed Server@42552c
java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.Server.doStart(Server.java:233)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.svse.jetty.JettyStarter.main(JettyStarter.java:20)
Exception in thread "main" java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:205)
at org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:304)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at org.mortbay.jetty.Server.doStart(Server.java:233)
at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
at com.svse.jetty.JettyStarter.main(JettyStarter.java:20)
解决方法:
默认equinox的jetty是使用 80端口,而在Linux下由于权限的关系,一般程序只能启用1024以上的端口,最简单的办法就是改变Jetty的启动端口让其大于1024,比如8080。
更多推荐
所有评论(0)