Exception in thread “main” java.lang.UnsatisfiedLinkError: no jzmq in java.library.path in Eclipse

心已入冬 提交于 2019-12-11 04:24:27

问题


Import org.zeromq.ZMQ;

-For the above import statement, I am using "org folder" in jzmq master folder which consists of ZMQ.java file.

-So, there is no problem with compilation. When I start running the program, It shows below exception

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jzmq in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at org.zeromq.ZMQ.(ZMQ.java:41) at server.main(Server.java:13)

What should I have to do? Which packages I have to download and which import statements I have to use for the ZeroMQ helloworld example in java?

I saw that many people are using libzmq.dll, jzmq.dll and some jar files somewhere to avoid that exception. But I want a clear answer.


回答1:


This lib (jzmq) is binding to the native library libzmq. If you don't use features of libzmq (ipc for example) you'd better to use full java implementation - jeromq (mvnrepo, jeromq git). It has almost the same functionality.

Otherwise if you need jzmq, you have to compile it properly. This is the way i compiled it on windows x64:

To build the library you need IDE Visual Studio 2010 or higher. In this example i used 2013 version. All work is performed in the directory C:\zmq (for example).

  1. Get the zeromq, jzmq and libsodium-1.0.10 sources.
  2. Copy the entire contents of zeromq directory to C:\zmq.
  3. Create a directory C:\zmq\java.
  4. Copy the entire contents of jzmq directory to C:\zmq\java.
  5. Create a directories C:\zmq\libsodium and C:\zmq\libsodium
  6. Copy to C:\zmq\libsodium\bin libsodium-1.0.10-msvc\Win32 and libsodium-1.0.10-msvc\x64 directories.
  7. Create a directory C:\zmq\libsodium\src.
  8. Copy to C:\zmq\libsodium\src directory libsodium-1.0.10-msvc\include.

Zeromq.

Open in Visual Studio the appropriate zeromq solution file from the directory C:\zmq\builds\msvc.

Open configuration manager. Active configuration solutions - choose DynRelease. Active solution platform - choose x64.

Open project properties page, go to Configuration Properties - C/C++ - General, check paths for include files directories.

Then select linker - General, and check paths for the libraries directories.

In the configuration file C:\zmq\builds\msvc\vs2013\libsodium.import.props correct path in the section.

Then buid it, if all was correct you will get dlls in C:\zmq\bin\x64\Release\v120\dynamic directory. If it wasn't - check out logs, make changes and rebuild it.


Jzmq.

Now open the appropriate jzmq solution file from the directory C:\zmq\java\builds\msvc\

As well as in zeromq project open configuration manager and select Release and x64 platform.

Open project properties page, go to Configuration Properties - VC ++ Directories and check that path where your JDK was installed is correct. You will se there something like this:

..\..\..\..\include;C:\Program Files\Java\jdk1.7.0_71\include;C:\Program
Files\Java\jdk1.7.0_71\include\win32;$(IncludePath)

Also check that Library Catalogues (forgot its name) path include path to the directory with built zeromq libs. It will look like this:

..\..\..\..\bin\x64\Release\v120\dynamic;$(LibraryPath)

On the properties page, go to Configuration Properties - assembly events - event before assembly and check property "Command Prompt" (first of all check paths to files in copy command). It will look like this:

copy ..\config.hpp "..\..\..\src\main\c++\"

Then buid jzmq, if all was correct you will get files in C:\zmq\java\lib.

If it wasn't - check out logs, make changes and rebuild it.


In the C:\zmq you need only bin java\lib directories, the rest can be removed.

Add to PATH the path to bin\x64\Release\v120\dynamic and run you java app with -Djava.library.path="path_to_java\lib"




回答2:


I had the same problem on Linux (eclipse), I solved it out by setting up the path of native library jzmq for my zmq.jar. By going into the project properties ( right click on project -> Properties... -> Java Build Path ), you can then add the JDIC.jar as a library on the library tab, expand it, and edit the Native Library Location property to point to the folder containing the native libraries:in my case it was /usr/local/lib.

So, basically, you could add -Djava.library.path it as a VM argument in the launch configuration or set the native library as specified in http://www.eclipsezone.com/eclipse/forums/t49342.html

I hope it will help people, who had this issue.

Have a good day.



来源:https://stackoverflow.com/questions/40436312/exception-in-thread-main-java-lang-unsatisfiedlinkerror-no-jzmq-in-java-libra

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