2014-11-03 92 views
1

目前我使用的是cometd 3.0.2(最新版本)。試圖做一個簡單的握手它給了我下面的錯誤:哪個版本的jetty兼容cometd-3.0.2

隨着碼頭7.4.4

java.lang.NoClassDefFoundError: org/eclipse/jetty/client/api/ContentProvider 

隨着碼頭9.2.3

java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ajax/JSON 

這是代碼,我試圖運行:

import java.util.HashMap; 
import java.util.Map; 
import org.cometd.client.BayeuxClient; 
import org.cometd.client.transport.ClientTransport; 
import org.cometd.client.transport.LongPollingTransport; 
import org.eclipse.jetty.client.HttpClient; 

public class MyClass { 

    public static void main(String[] args) throws Exception { 

     // Create (and eventually set up) Jetty's HttpClient: 
     HttpClient httpClient = new HttpClient(); 
     // Here set up Jetty's HttpClient, for example: 
     // httpClient.setMaxConnectionsPerAddress(2); 
     httpClient.start(); 

     // Prepare the transport 
     Map<String, Object> options = new HashMap<String, Object>(); 
     ClientTransport transport = new LongPollingTransport(options, httpClient); 

     BayeuxClient client = new BayeuxClient("http://localhost:8080/cometd", transport); 
     client.handshake(); 
     boolean handshaken = client.waitFor(1000, BayeuxClient.State.CONNECTED); 
     if (handshaken) { 
      System.out.println("Yey"); 
     } 
    } 
} 

有沒有人知道碼頭是否兼容最新cometd?或者其他任何cometd

+0

如果您使用的是maven,您可以發佈您的pom.xml嗎? – 2014-11-03 22:12:09

+0

我沒有使用maven。我一定要嗎?對不起,我是新手。 – Dimme 2014-11-03 22:58:04

+0

Maven並不是必需的,但是由於存在如此多的依賴關係,您可能需要研究maven或ant + ivy或gradle(真正的任何其他構建工具可以實現適當的傳遞依賴關係解析)。由於你所描述的問題只是尖叫壞/遺漏/錯位的文物。 – 2014-11-03 23:23:53

回答

1

CometD 3可以與任何Servlet 3.0或更高版本的Servlet容器一起使用。 Jetty 9.2.x是推薦使用的Servlet容器。

話雖如此,Joakim正確地說CometD依賴於其他庫,因此您應該使用構建工具爲您完成這項工作。 Maven是這樣推薦的工具。

看一看更新installation instructions,在primer,並在tutorials上手。

我建議您按照底漆說明操作。即使你不喜歡Maven,你可以暫時安裝它,按照底漆,一旦你有了底層的CometD應用程序,你可以卸載Maven,如果你願意的話(但是你自己去建立你的應用程序)。

相關問題