I am trying to connect to a erlang node with java but I get an error. To start erlang I used this command erl -sname db -setcookie erlang
.
This is my java code:
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");
}
}
It compiles fine but then I get a runtime error and I have no idea what it means
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
Please, can anyone give me a solution to my problem.