No jzmq in java.library.path

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 05:42:27

Ok. So, let's get hands dirty together:

to see on your machine, if this works as it ought, after a due installation, or not:

One of the simplest formal-archetype is a REQ/REP example, that uses two parts, one - a "server":

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

public class rrserver{
    public static void main (String[] args) {
        Context context = ZMQ.context(1);

        //  Socket to talk to clients
        Socket responder  = context.socket(ZMQ.REP);
        responder.bind("tcp://localhost:5560");

        System.out.println("launch and connect server.");

        while (!Thread.currentThread().isInterrupted()) {
            //  Wait for next request from client
            byte[] request = responder.recv(0);
            String string = new String(request);
            System.out.println("Received request: ["+string+"].");

            //  Do some 'work'
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            //  Send reply back to client
            responder.send("World".getBytes(), 0);
        }

        //  We never get here but clean up anyhow
        responder.close();
        context.term();
    }
}

and another part, a "client":

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

public class rrclient{

    public static void main(String[] args) {
        Context context = ZMQ.context(1);

        //  Socket to talk to server
        Socket requester = context.socket(ZMQ.REQ);
        requester.connect("tcp://localhost:5560"); // REF ABOVE AND LET START THIS AFTER "server"

        System.out.println("launch and connect client.");

        for (int request_nbr = 0; request_nbr < 10; request_nbr++) {
            requester.send("Hello", 0);
            String reply = requester.recvStr(0);
            System.out.println("Received reply " + request_nbr + " [" + reply + "]");
        }

        //  We never get here but clean up anyhow
        requester.close();
        context.term();
    }
}

This ought get up and running quite fast to show, if the installation was done right or not. Code was borrowed from ZeroMQ published trivial examples for inspiration.

If indeed serious about going into a domain of distributed computing, do not hesitate to read a great book from Pieter HINTJENS, "Code Connected, Volume 1" ( also available in pdf ). Worth time and efforts.

Madpoptart

On OSX I was having a similar problem. I installed ZMQ using these instructions.

The last step says to set library path with -Djava.library.path=/usr/local/lib.

I found it much easier to simply add the path into

~/.bash_profile

for example:

echo "export JAVA_LIBRARY_PATH=$JAVA_LIBRARY_PATH:/usr/local/lib" >> ~/.bash_profile

After restarting Intellij it was able to correctly find libjzmq.

Also it may be a good idea to export the DYLD_LIBRARY_PATH as well if you are planning on doing any C/C++ development.

Simply add

export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/lib"

to

~/.bash_profile.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!