# HiveMq Java Client

**URL:** <https://forum.inductiveautomation.com/t/hivemq-java-client/85583>\
**Category:** Ignition\
**Created:** [February 12, 2024, 7:42pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583 "2024-02-12T19:42:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 12, 2024, 7:42pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/1 "2024-02-12T19:42:22Z")

</div>

Has anyone been able to successfully use the HiveMQ java client within Ignition? I have added the jar to my gateways common library folder and I am running the code in the gateway scope. I keep getting stuck on the following:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d89cdda29db5bebbe1702723300875a9a76045a3.png)

> Caused by: org.python.core.PyException: java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class com.hivemq.client.internal.mqtt.MqttClientTransportConfigImpl
> 
> ... 23 common frames omitted
> 
> Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.hivemq.client.internal.mqtt.MqttClientTransportConfigImpl
> 
> at com.hivemq.client.internal.mqtt.MqttRxClientBuilderBase.(MqttRxClientBuilderBase.java:46)
> 
> at com.hivemq.client.internal.mqtt.MqttRxClientBuilderBase$Choose.(MqttRxClientBuilderBase.java:216)
> 
> at com.hivemq.client.mqtt.MqttClient.builder(MqttClient.java:59)
> 
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 
> at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> 
> at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> 
> at java.base/java.lang.reflect.Method.invoke(Unknown Source)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:190)
> 
> ... 20 common frames omitted

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 12, 2024, 7:44pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/2 "2024-02-12T19:44:35Z")

</div>

Tip: post code - not pictures of code. That way it doesn't have to be typed out in answers to your question. Post a screengrab _as well_ if the context is relevant to the question. See [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831).

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 12, 2024, 7:48pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/3 "2024-02-12T19:48:16Z")

</div>

What jar file(s) have you added?

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 12, 2024, 7:49pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/4 "2024-02-12T19:49:44Z")

</div>

hivemq-mqtt-client-1.3.3.jar found here [Maven Repository: com.hivemq » hivemq-mqtt-client » 1.3.3 (mvnrepository.com)](https://mvnrepository.com/artifact/com.hivemq/hivemq-mqtt-client/1.3.3)

Is there a dependency that I am unaware of?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 12, 2024, 7:50pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/5 "2024-02-12T19:50:42Z")

</div>

[Seems so](https://github.com/hivemq/hivemq-mqtt-client/blob/bb5dee551e1e19edbc4d6a9b19037a616a05db4f/build.gradle.kts#L66-L84)

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 12, 2024, 8:30pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/6 "2024-02-12T20:30:25Z")

</div>

Are those dependencies for building the jar or are those dependencies outside the jar that are needed to use the jar?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 12, 2024, 8:45pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/7 "2024-02-12T20:45:48Z")

</div>

Any of those JARs that aren't already part of Ignition are at least needed at runtime for execution. And so on if they have any of their own dependencies.

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 13, 2024, 5:21pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/8 "2024-02-13T17:21:41Z")

</div>

Thanks. I was able to get passed that error. I built the shaded JAR and then it still had a dependency that was not being included in the shaded JAR for rxjava-2.2.21.jar. I just added that JAR separate in the common folder.

Now, I am getting stuck on a different error. Could you shine any light on what might be causing this?

Following an example from [here](https://www.hivemq.com/article/mqtt-client-api/the-hivemq-mqtt-client-library-for-java-and-its-blocking-api-flavor/) looks like it is failing on line 16 where it does .payload()

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/5/05ba74bae6cf07ee79e0c7a8fbf1743b908b3e44.png)

> com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 16, in handleMessage at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source) at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalAccessException: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"
> 
> at org.python.core.Py.JavaError(Py.java:547)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:192)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:208)
> 
> at org.python.core.PyObject. **call** (PyObject.java:477)
> 
> at org.python.core.PyObject. **call** (PyObject.java:481)
> 
> at org.python.core.PyMethod. **call** (PyMethod.java:141)
> 
> at org.python.pycode.\_pyx1282.handleMessage$1(:24)
> 
> at org.python.pycode.\_pyx1282.call\_function()
> 
> at org.python.core.PyTableCode.call(PyTableCode.java:173)
> 
> at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
> 
> at org.python.core.PyFunction.function\_\_\_call\_\_(PyFunction.java:474)
> 
> at org.python.core.PyFunction. **call** (PyFunction.java:469)
> 
> at org.python.core.PyFunction. **call** (PyFunction.java:464)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:847)
> 
> at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:829)
> 
> at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:852)
> 
> at com.inductiveautomation.ignition.common.script.message.MessageHandlerRunnable.run(MessageHandlerRunnable.java:114)
> 
> at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
> 
> at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
> 
> at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
> 
> at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> 
> at java.base/java.lang.Thread.run(Unknown Source)
> 
> Caused by: org.python.core.PyException: java.lang.IllegalAccessException: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"
> 
> ... 23 common frames omitted
> 
> Caused by: java.lang.IllegalAccessException: class org.python.core.PyReflectedFunction cannot access a member of class com.hivemq.client.internal.mqtt.message.publish.MqttPublishBuilder$Base with modifiers "public"
> 
> at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Unknown Source)
> 
> at java.base/java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
> 
> at java.base/java.lang.reflect.Method.invoke(Unknown Source)
> 
> at org.python.core.PyReflectedFunction. **call** (PyReflectedFunction.java:190)
> 
> ... 21 common frames omitted

---

<div class="post-metadata">

**Author:** ![Jonathan](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@Jonathan](https://forum.inductiveautomation.com/u/Jonathan)\
**Post date:** [February 13, 2024, 7:29pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/9 "2024-02-13T19:29:26Z")

</div>

Finally figured it out, with the help of this post [Using Java.net Socket - #13 by pturmel](https://forum.inductiveautomation.com/t/using-java-net-socket/79962/13)

Looks like this last error had to do with Java overloading methods. Using reflection I can get the method from the class using the method name and parameter types. Then once I get the method from the class I can use the invoke method on the method returned from get method passing in my instance of the class object, along with parameter values. This is on line 22 and 24.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/4/84c1d4faeece7413ee24ecb014a6b624c5f964d7.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 13, 2024, 7:56pm UTC](https://forum.inductiveautomation.com/t/hivemq-java-client/85583/10 "2024-02-13T19:56:11Z")

</div>

Yuck, good job figuring that out. Not sure I would have ended up there.
