Installing the Java ZeroMQ binding (jzmq) using Maven, Missing Native Code Library
Asked Answered
N

2

11

I am attempting to install jzmq, the Java ZeroMQ binding, from the Maven repository (http://search.maven.org/#search|ga|1|a%3A%22jzmq%22). When added as a dependency to my pom.xml[1] Maven downloads the main jar, which provides a Java library, as expected. In addition to the main library, jzmq requires a native code library which Maven does not appear to download. At run time the Java library raises an exception due to the missing native code library.

The native library is provided in the repository and the pom.xml[2] file for jzmq appears to specify that the native library (libjzmq.so) should be downloaded. If I download the library and set the native library location manually it all works, I would however prefer if this could be automated via Maven.

I am unsure as to why Maven is not downloading and installing the native library, any advice or suggestions as to how to resolve this problem would be greatly appreciated.

I am running the latest Ubuntu release using OpenJDK and Apache Maven 3.0.4

[0] The exception that is raised when using jzmq as provided by Maven, sans the crucial native code library.

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jzmq in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1874)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at org.zeromq.ZMQ.<clinit>(ZMQ.java:39)

[1] My pom.xml where jzmq is added as a dependency

<dependency>
<GroupId>org.zeromq</groupId>
<artifactId>jzmq</artifactId>
version>2.2.2</version>
</dependency>

[2] The pom.xml for jzmq where the native library is referred to

<profile>
<id>Linux</id>
<activation>
<property>
<name>os.name</name>
<value>Linux</value>
</property></activation>
<properties>
<native.os>${os.name}</native.os>
<native.path>src/.libs/libjzmq.so</native.path>
<!-- Use platform-specific path separators here: -->
<native.library-path>src/.libs/</native.library-path>
</properties>
</profile>
Narghile answered 19/9, 2013 at 18:29 Comment(0)
P
5

You need tell Java where to find the native library.

java -Djava.library.path=/usr/local/lib xxxxx 

To run jzmq, you need 2 things,

  1. /usr/local/share/java/zmq.jar
  2. native library, (libjzmq.dylib or libjzmq.dll or libjzmq.so)

refer to http://zeromq.org/bindings:java for detail

To avoid the configuration trouble, I believe you can check how to embed the native lib. When class "org.zeromq.ZMQ" initialises itself, it will try to load the embedded lib first,

static {
       // if no embedded native library, revert to loading from java.library.path
    if (!EmbeddedLibraryTools.LOADED_EMBEDDED_LIBRARY)
        System.loadLibrary("jzmq");
}
Penn answered 8/1, 2014 at 3:49 Comment(0)
N
1

Alternatively, if you prefer not to use the native library and you just want to get started quickly you can opt to use the java equivalent of zeromq library by adding below to your pom.xml

 <dependency>
    <groupId>org.zeromq</groupId>
    <artifactId>jeromq</artifactId>
    <version>0.5.2</version>
 </dependency>

For more details in the difference you may refer to an answered question here:

For an up to date list of jeromq versions see the mvnrepository here

Nigercongo answered 2/6, 2020 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.