简体   繁体   English

如何将外部jars添加到Webots?

[英]How to add external jars to Webots?

I'm trying to add external jar to a Webots project.我正在尝试将外部 jar 添加到 Webots 项目中。 In IntelliJ i can just do project structure -> modules -> dependencies -> add, to add the external jar.在 IntelliJ 中,我可以只执行项目结构 -> 模块 -> 依赖项 -> 添加,以添加外部 jar。 How to do this in Webots?如何在 Webots 中做到这一点? I've tried to change the classpath, but no success..我试图改变类路径,但没有成功..

I get this error: socket.java:1: error: package org.java_websocket.client does not exist , eventhough i have the jars on my computer.我收到此错误: socket.java:1: error: package org.java_websocket.client does not exist ,尽管我的计算机上有 ZBE1587EA25D1C05C81D3BDE9C4C960B.0

Edit in response to Olivier:编辑回应奥利维尔:

[environment variables with paths]
CLASSPATH = ../jars/Java-WebSocket-1.3.8.jar
JAVA_LIBRARY_PATH = ../jars

[java]
COMMAND = javaw.exe
OPTIONS = -Xms6144k

I've added the code above, but this didn't work.我已经添加了上面的代码,但这不起作用。

Also, i could provide StackOverflow with my code.另外,我可以为 StackOverflow 提供我的代码。 Here it is:这里是:

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;
import org.json.JSONObject;

import java.net.URI;
import java.net.URISyntaxException;

public class socket {

  public static void main(String args[]) throws URISyntaxException, InterruptedException {


    WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8000"), new Draft_6455()) {
      @Override
      public void onMessage(String message) {
        JSONObject obj = new JSONObject(message);
        String channel = obj.getString("channel");
      }

      @Override
      public void onOpen(ServerHandshake handshake) {
        System.out.println("opened connection");
        this.send("Connection opened");

      }

      @Override
      public void onClose(int code, String reason, boolean remote) {
        System.out.println("closed connection");
      }

      @Override
      public void onError(Exception ex) {
        ex.printStackTrace();
      }

    };

    //open websocket
    mWs.connectBlocking();
    JSONObject obj = new JSONObject();
    obj.put("event", "addChannel");
    obj.put("channel", "ok_btccny_ticker");
    String message = obj.toString();
    //send message
//    mWs.send(message);
  }
}

And the errors:和错误:

    javac -Xlint -classpath "C:\Users\user\AppData\Local\Programs\Webots\lib\controller\java\Controller.jar;;." socket.java
socket.java:1: error: package org.java_websocket.client does not exist
import org.java_websocket.client.WebSocketClient;
                                ^
socket.java:2: error: package org.java_websocket.drafts does not exist
import org.java_websocket.drafts.Draft_6455;
                                ^
socket.java:3: error: package org.java_websocket.handshake does not exist
import org.java_websocket.handshake.ServerHandshake;
                                   ^
socket.java:4: error: package org.json does not exist
import org.json.JSONObject;
               ^
socket.java:14: error: cannot find symbol
    WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8000"), new Draft_6455()) {
    ^
  symbol:   class WebSocketClient
  location: class socket
socket.java:14: error: cannot find symbol
    WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8000"), new Draft_6455()) {
                              ^
  symbol:   class WebSocketClient
  location: class socket
socket.java:14: error: cannot find symbol
    WebSocketClient mWs = new WebSocketClient(new URI("ws://localhost:8000"), new Draft_6455()) {
                                                                                  ^
  symbol:   class Draft_6455
  location: class socket
socket.java:22: error: cannot find symbol
      public void onOpen(ServerHandshake handshake) {
                         ^
  symbol: class ServerHandshake
socket.java:15: error: method does not override or implement a method from a supertype
      @Override
      ^
socket.java:17: error: cannot find symbol
        JSONObject obj = new JSONObject(message);
        ^
  symbol: class JSONObject
socket.java:17: error: cannot find symbol
        JSONObject obj = new JSONObject(message);
                             ^
  symbol: class JSONObject
socket.java:21: error: method does not override or implement a method from a supertype
      @Override
      ^
socket.java:24: error: cannot find symbol
        this.send("Connection opened");
            ^
  symbol: method send(String)
socket.java:28: error: method does not override or implement a method from a supertype
      @Override
      ^
socket.java:33: error: method does not override or implement a method from a supertype
      @Override
      ^
15 errors
printing javac parameters to: C:\Users\user\Documents\my_project3\controllers\socket\javac.20200527_102128.args
Nothing to be done for build targets.

As you can see, i get override errors because Webots can't find the jar that holds the methods/functions.如您所见,我收到覆盖错误,因为 Webots 找不到包含方法/功能的 jar。

You should define the CLASSPATH variable in the runtime.ini file of your robot controller as explained here :您应该机器人 controller 的runtime.ini文件中定义CLASSPATH变量,如下所述:

; runtime.ini for a Java controller on Windows

[environment variables with paths]
CLASSPATH = ../lib/MyLibrary.jar
JAVA_LIBRARY_PATH = ../lib

[java]
COMMAND = javaw.exe
OPTIONS = -Xms6144k

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

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