0
我想用java連接到erlang節點,但出現錯誤。要啓動erlang,我使用了這個命令erl -sname db -setcookie erlang
。使用JInterface連接java與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");
}
}
它編譯罰款,但後來我得到一個運行時錯誤,我不知道這意味着什麼
[email protected]:~/erlang/projekt$ javac -classpath "/usr/lib/erlang/lib/jinterface-1.6.1/priv/OtpErlang.jar:." ErlConnection.java
[email protected]:~/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
請,誰能給我一個解決方案對我的問題。
這就是我得到: 'MIRT @ Ubuntu的:〜/二郎/ PROJEKT $ java命令 「/usr/lib/erlang/lib/jinterface-1.6.1/priv/OtpErlang.jar:」。 ErlConnection.java 錯誤:無法找到或加載主類ErlConnection.java' –