如何向Webot添加外部jar?

问题描述 投票:0回答:1

我正在尝试将外部jar添加到Webots项目。在IntelliJ中,我只能执行项目结构->模块->依赖项->添加,以添加外部jar。如何在Webots中做到这一点?我试图更改类路径,但没有成功。.

尽管我的计算机上有罐子,但出现此错误:socket.java:1: error: package org.java_websocket.client does not exist。>>

编辑以回应奥利维尔:

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

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

我已经在上面添加了代码,但这没有用。

另外,我可以为StackOverflow提供我的代码。这是:

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

和错误:

    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.

如您所见,由于Webots找不到保存方法/函数的jar,因此我得到了覆盖错误。

我正在尝试将外部jar添加到Webots项目。在IntelliJ中,我只能执行项目结构->模块->依赖项->添加,以添加外部jar。如何在Webots中做到这一点?我尝试过...

java jar classpath webots
1个回答
1
投票

您应按照CLASSPATH的说明在机器人控制器的runtime.ini文件中定义here变量:

© www.soinside.com 2019 - 2024. All rights reserved.