错误:软件包org.zeromq.ZMQ不存在

时间:2018-10-12 17:26:31

标签: java zeromq jzmq

我正在尝试在Windows 10 OS中运行Zeromq Java程序。为了设置环境,我尝试执行以下操作。

1)从此处http://zeromq.org/distro:microsoft-windows下载并安装ZMQ的Java库。

2)在环境变量中添加路径。

3)尝试从zguide运行简单的Hello World代码。

服务器:

import org.zeromq.ZMQ;

public class Hwserver {

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

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

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

        // Do some 'work'
        Thread.sleep(1000);

        // Send reply back to client
        String reply = "World";
        responder.send(reply.getBytes(), 0);
    }
    responder.close();
    context.term();
}
}

客户:

import org.zeromq.ZMQ;

public class Hwclient {

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

    //  Socket to talk to server
    System.out.println("Connecting to hello world server…");

    ZMQ.Socket requester = context.socket(ZMQ.REQ);
    requester.connect("tcp://localhost:5555");

    for (int requestNbr = 0; requestNbr != 10; requestNbr++) {
        String request = "Hello";
        System.out.println("Sending Hello " + requestNbr);
        requester.send(request.getBytes(), 0);

        byte[] reply = requester.recv(0);
        System.out.println("Received " + new String(reply) + " " + requestNbr);
    }
    requester.close();
    context.term();
}
}

当我尝试编译服务器时,出现以下错误。

error: cannot find symbol import org.zeromq.ZMQ; 

之后,我尝试手动安装该库。我做了以下事情。

1)从Github下载并解压缩了Libzmq-master和jzmq-master。

2)使用Visual Studio 2017尝试从此处的目录构建libzmq.sln和msvc.sln

libzmq-libzmq-master \ builds \ deprecated-msvc \ vs2017 \ libzmq.sln

jzmq-jzmq-master \ jzmq-jni \ builds \ msvc \ msvc.sln

但是无法构建它。查找几个错误。例如:

libzmq-#错误:未定义ZMQ_IOTHREAD_POLLER_USE_ *宏(编译源文件........ \ src \ client.cpp)libzmq c:\ users \ shiha \ downloads \ libzmq-master \ src \ poller.hpp

jzmq-无法打开包含文件:'zmq.h':没有此类文件或目录

我没有弄错我在做什么。我已遵循zeromq.org中提供的指南,并且也搜索了类似的问题。但是找不到解决方案。

0 个答案:

没有答案