简体   繁体   English

无法使用Californium Java库设置CoAP服务器

[英]Unable to Setup CoAP Server using Californium Java Library

I am trying to setup CoAP Server using Java library from http://mvnrepository.com/artifact/org.eclipse.californium/californium-core/1.0.1 我正在尝试使用来自http://mvnrepository.com/artifact/org.eclipse.californium/californium-core/1.0.1的 Java库设置CoAP Server

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());
        }
    }

adding endpoints to server causing below Exception: 将端点添加到服务器,导致以下异常:

Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/californium/elements/RawDataChannel at com.landisgyr.chardonnay.HelloWorldServer.main(HelloWorldServer.java:35) Caused by: java.lang.ClassNotFoundException: org.eclipse.californium.elements.RawDataChannel at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more 线程“主”中的异常java.lang.NoClassDefFoundError:com.landisgyr.chardonnay.HelloWorldServer.main(HelloWorldServer.java:35)上的org / eclipse / californium / elements / RawDataChannel造成原因:java.lang.ClassNotFoundException:org.eclipse java.net.URLClassLoader.findClass的.californium.elements.RawDataChannel(java.lang.ClassLoader.loadClass的未知源)(sun.misc.Launcher $ AppClassLoader.loadClass的未知源)(java.lang.ClassLoader处) .loadClass(未知来源)...还有1个

Is there anyone who go CoAP server working with Californium Java library ? 有谁去过CoAP服务器使用Californium Java库吗?

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

It looks like some parts of the project are missing. 看起来项目的某些部分丢失了。

Here is a step-by-step tutorial to run the CoAP HelloWorldServer. 这是运行CoAP HelloWorldServer的分步教程。

Requirements : Eclipse (+ Egit & Maven Integration Extenstions) , Git , Maven 要求 :Eclipse(+ Egit和Maven集成扩展),Git,Maven

  1. Open Terminal and execute following commands: 打开终端并执行以下命令:

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

sudo mvn clean install
  1. Open Eclipse and import the Maven Project 打开Eclipse并导入Maven项目

  2. After import launch the "HelloWorldServer.java". 导入后,启动“ HelloWorldServer.java”。 If anything done correctly it should work. 如果一切正确完成,它应该可以工作。

Endpoint started and working 端点已启动且正在运行

  1. To test if the resource is avaiable i recommend the Firefox extension "Cupper" which is able to speak CoAP. 要测试资源是否可用,我建议使用能够说出CoAP的Firefox扩展“ Cupper”。 You just need to open the following URI: coap://localhost:5683 您只需要打开以下URI:coap:// localhost:5683

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM