Loading library from external jar

Hi,
I’m trying to make use of the mbus bridge that is implemented in feature/mbus_bridge_abb_b23. The implementation uses org.openmuc.jmbus as an external jar. The bundle dependencies (import/export) are not the problem as far as I understand and I checked all the setup parts as described in https://community.openems.io/t/how-to-integrate-an-external-library/62. But when I try to activate the mbus bridge bundle some library that is needed in jmbus cannot be loaded. I get the same error
(Could not load lib from jar and from system. gnu.io.LibLoadException: directory does not exist /libs)
that is also discussed here.

The answer that seemed to work there is:
"…add a plugin to the maven build which produces a JAR with all dependencies included. Like described here: https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/ However, what’s still odd, you have to add the library path like mentioned above:

-Djava.library.path=/usr/lib/jni

For my understanding this should not be necessary anymore. Nevertheless, without the path it is not working.
"
Now my question is, given that this would be the only solution, what is the best way to do this? I’m not the biggest expert in maven, gradle, etc. and I don’t quite look through all the details of plugin integration in bnd so maybe I just missed something dumb …

Thanks in advance,
Erik

Hi Erik,

I’ll ping @ljonka here, as he is the author of the pull-request.

I was not able to try the mbus bridge yet, as I don’t have a device here to test with. But during the last weeks I developed a OneWire bridge which also uses RXTX for serial access (it’s in review currently: https://github.com/OpenEMS/openems/pull/891). So I gained some knowledge about JNI.

The problem with RXTX is, that it does not bring its own native JNI library, so that has to be installed manually. This is a problem, that is solved in jSerialComm, that is used for the Modbus communication by j2mod.

I found some documentation on OpenMUCs jmbus implementation here, here and here. If you run your JAR file on a Debian based linux, it should be sufficient to execute

sudo apt-get install librxtx-java

Keep me updated.
Regards, Stefan

Hi Stefan,
Thanks for your quick reply! You were right with the RXTX/JNI Problem, having rxtx installed it worked for me executing OpenEMS as a jar with the argument -Djava.library.path=/usr/lib/jni (on linux).

I found a workaround that allows me to start it in Eclipse, too, which wasn’t possible before (https://stackoverflow.com/questions/10751304/java-lang-unsatisfiedlinkerror-no-rxtxserial-in-java-library-path-thrown-while if someone has similar problems) so that’s fine for me now. Just in general though, how would you add a system property as an argument if you want to start through Eclipse?

Greetings, Erik

System properties are defined in the bndrun file: https://github.com/OpenEMS/openems/blob/develop/io.openems.edge.application/EdgeApp.bndrun#L7

I tried that already and had no success. But that could have had other reasons of course. Thank you!

So did the mbus-bridge work for you? As I am not able to test it myself, I was not able to approve the pull-request till now. If it worked for you I can approve it - or at least only concentrate on coding guideline mistakes.It might help if you or @ljonka could provide a readme.adoc file that explains the steps to make it work. See my OneWire-bundle readme for an example.

Thanks!

I made some adjustments to it so that it works for me now, but on https://github.com/erik40021/openems/tree/feature/mbus. I added a small readme, too.
Hope this helps!

I merged the pull-request and your changes to develop yesterday. Thank you!