【问题标题】:Unable to Setup CoAP Server using Californium Java Library无法使用 Californium Java 库设置 CoAP 服务器
【发布时间】:2016-01-25 07:41:11
【问题描述】:

我正在尝试使用来自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());
        }
    }

向服务器添加端点导致以下异常:

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

有没有人在 CoAP 服务器上使用 Californium Java 库?

【问题讨论】:

标签: java eclipse coap


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    项目的某些部分似乎丢失了。

    这是运行 CoAP HelloWorldServer 的分步教程。

    要求:Eclipse(+ Egit 和 Maven 集成扩展)、Git、Maven

    1. 打开终端并执行以下命令:

    sudo git clone https://github.com/eclipse/californium.core.git

    sudo mvn clean install
    
    1. 打开 Eclipse 并导入 Maven 项目

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

    Endpoint started and working

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-14
      • 1970-01-01
      相关资源
      最近更新 更多