2013-11-09 63 views
0

我希望我的服务器(码头)通过网络在特定地址访问。 如何配置jetty服务器以使用外部地址,例如:my_address_name.org或其他内容。Java码头外部地址

因为默认情况下:

server = new Server(port); 
     WebAppContext context = new WebAppContext(); 

     context.setResourceBase(app_path); 
     context.setDescriptor(app_path + "WEB-INF/web.xml"); 

     context.setConfigurations(new Configuration[] { 
       new AnnotationConfiguration(), new WebXmlConfiguration(), 
       new WebInfConfiguration(), new TagLibConfiguration(), 
       new PlusConfiguration(), new MetaInfConfiguration(), 
       new FragmentConfiguration(), new EnvConfiguration() }); 

     context.setContextPath(context_path); 
     context.setParentLoaderPriority(true); 
     server.setHandler(context); 

     try { 
      server.start(); 
      server.join(); ... 

它运行在本地主机...

回答

0

这个例子将绑定到特定的IP和端口9090听:

Connector con = new SelectChannelConnector(); 
con.setHost("192.168.1.20"); 
con.setPort(9090); 
server.addConnector(con); 

(如果我没记错以及Jetty总是默认绑定到所有IP(0.0.0.0))。