我正在尝试使用java连接到erlang节点,但是我收到错误。要启动erlang,我使用了这个命令erl -sname db -setcookie erlang
。
这是我的java代码:
import com.ericsson.otp.erlang.OtpConnection;
import com.ericsson.otp.erlang.OtpErlangObject;
import com.ericsson.otp.erlang.OtpPeer;
import com.ericsson.otp.erlang.OtpSelf;
public class ErlConnection {
private static OtpConnection conn;
public OtpErlangObject received;
private final String peer;
private final String cookie;
public static void main(String []args){
new ErlConnection("db","erlang");
}
public ErlConnection(String _peer, String _cookie) {
peer = _peer;
cookie = _cookie;
connect();
/*Do Calls to Rpc methods and then close the connection*/
disconnect();
}
private void connect() {
System.out.print("Please wait, connecting to "+peer+"....\n");
String javaClient ="java";
try {
OtpSelf self = new OtpSelf(javaClient, cookie.trim());
OtpPeer other = new OtpPeer(peer.trim());
conn = self.connect(other);
System.out.println("Connection Established with "+peer+"\n");
}
catch (Exception exp) {
System.out.println("connection error is :" + exp.toString());
exp.printStackTrace();
}
}
public void disconnect() {
System.out.println("Disconnecting....");
if(conn != null){
conn.close();
}
System.out.println("Successfuly Disconnected");
}
}
它编译得很好,但后来我遇到了运行时错误,我不知道它意味着什么
mirt@ubuntu:~/erlang/projekt$ javac -classpath "/usr/lib/erlang/lib/jinterface-1.6.1/priv/OtpErlang.jar:." ErlConnection.java
mirt@ubuntu:~/erlang/projekt$ java ErlConnection
Please wait, connecting to db....
Exception in thread "main" java.lang.NoClassDefFoundError: com/ericsson/otp/erlang/OtpSelf
at ErlConnection.connect(ErlConnection.java:33)
at ErlConnection.<init>(ErlConnection.java:21)
at ErlConnection.main(ErlConnection.java:15)
Caused by: java.lang.ClassNotFoundException: com.ericsson.otp.erlang.OtpSelf
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
拜托,任何人都可以帮我解决问题。
答案 0 :(得分:0)
我认为问题在于,当您运行HBox hb = null;
以再次使用for(int i =0: i < your_number_of_HBoxes; i++){
hb = HBox hb = new HBox(10);
root.getChildren().add(rect);
}
选项运行程序时,需要包含Jinterface库。考虑编写一个shell脚本或批处理文件来处理启动所有内容。
我还建议使用像Maven或Gradle这样的构建系统来管理Jinterface等依赖项,并处理构建Java程序。