2013-11-09 67 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))。