如何将外部 jar 添加到 Webots?
How to add external jars to Webots?
我正在尝试将外部 jar 添加到 Webots 项目。在 IntelliJ 中,我可以只执行项目结构 -> 模块 -> 依赖项 -> 添加,以添加外部 jar。如何在 Webots 中执行此操作?我试图更改类路径,但没有成功..
我收到此错误:socket.java:1: error: package org.java_websocket.client does not exist
,尽管我的计算机上有 jar。
编辑以回应 Olivier:
[environment variables with paths]
CLASSPATH = ../jars/Java-WebSocket-1.3.8.jar
JAVA_LIBRARY_PATH = ../jars
[java]
COMMAND = javaw.exe
OPTIONS = -Xms6144k
我已经添加了上面的代码,但这没有用。
此外,我可以向 Whosebug 提供我的代码。这是:
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 无法找到包含 methods/functions.
的 jar
您应该按照解释 here:
在机器人控制器的 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
我正在尝试将外部 jar 添加到 Webots 项目。在 IntelliJ 中,我可以只执行项目结构 -> 模块 -> 依赖项 -> 添加,以添加外部 jar。如何在 Webots 中执行此操作?我试图更改类路径,但没有成功..
我收到此错误:socket.java:1: error: package org.java_websocket.client does not exist
,尽管我的计算机上有 jar。
编辑以回应 Olivier:
[environment variables with paths]
CLASSPATH = ../jars/Java-WebSocket-1.3.8.jar
JAVA_LIBRARY_PATH = ../jars
[java]
COMMAND = javaw.exe
OPTIONS = -Xms6144k
我已经添加了上面的代码,但这没有用。
此外,我可以向 Whosebug 提供我的代码。这是:
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 无法找到包含 methods/functions.
的 jar您应该按照解释 here:
在机器人控制器的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