无法使用Californium Java Library

时间:2016-01-25 07:41:12

标签: java eclipse coap

我正在尝试使用http://mvnrepository.com/artifact/org.eclipse.californium/californium-core/1.0.1

中的Java库设置CoAP服务器
public class HelloWorldServer extends CoapServer {

    private static final int COAP_PORT = 5683; 
    /*
     * Application entry point.
     */
    public static void main(String[] args) {

        try {

            // create server
            HelloWorldServer server = new HelloWorldServer();
            // add endpoints on all IP addresses
            server.addEndpoint(new CoAPEndpoint(new InetSocketAddress("127.0.0.1", COAP_PORT)));
            server.start();

        } catch (SocketException e) {
            System.err.println("Failed to initialize server: " + e.getMessage());
        }
    }

将端点添加到服务器,导致以下异常:

  

线程“main”中的异常java.lang.NoClassDefFoundError:   org / eclipse / californium / elements / RawDataChannel at   com.landisgyr.chardonnay.HelloWorldServer.main(HelloWorldServer.java:35)   引起:java.lang.ClassNotFoundException:   org.eclipse.californium.elements.RawDataChannel at   java.net.URLClassLoader.findClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)at   sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)at   java.lang.ClassLoader.loadClass(未知来源)......另外1个

是否有人将CoAP服务器与Californium Java库一起使用?

2 个答案:

答案 0 :(得分:1)

您需要将element-connector导入Eclipse项目。

答案 1 :(得分:0)

看起来项目的某些部分缺失。

以下是运行CoAP HelloWorldServer的分步教程。

要求:Eclipse(+ Egit& Maven Integration Extenstions),Git,Maven

  1. 打开终端并执行以下命令:
  2. $window.sessionStorage.token

    sudo git clone https://github.com/eclipse/californium.core.git
    1. 打开Eclipse并导入Maven项目

    2. 导入后启动“HelloWorldServer.java”。如果任何事情做得正确它应该工作。

    3. Endpoint started and working

      1. 为了测试资源是否可用,我推荐使用能够说CoAP的Firefox扩展“Cupper”。您只需要打开以下URI:coap:// localhost:5683