Spen Spen - 4 months ago 21x
Java Question

No dhtreader in java.library.path

I try to get this maven projekt to run on the Raspberry Pi 3 but the DHT11 sensor gives me the following error:

sudo java -classpath '.:classes:*:classes:/opt/pi4j/lib/*' com.epam.llpd.greenhouse.web.ServerStarter

java.lang.UnsatisfiedLinkError: no dhtreader in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.epam.llpd.greenhouse.sensor.Sensor.<clinit>(Sensor.java:16)
at com.epam.llpd.greenhouse.PiHardwareController$1.run(PiHardwareController.java:132)

In the folder
there is the

I did compile a binary objekt with the following command:

gcc -o dhtreader.so -lc -shared -I/usr/lib/jvm/jdk-7-oracle-arm-vfp-hflt/include -I/usr/lib/jvm/jdk-7-oracle-arm-vfp-hflt/include/linux dhtreader.c -l bcm2835

is placed in the same folder as the

The dhtreader.c file is a common C class specific for the Raspberry Pi to use the DHT11 and DHT22 sensor and it is used in many Raspberry Pi projects and has alot of sources like this one.

This C class (dhtreader.c) is used via. JNI/C but it just doesn't work because of the error above.

I allready tried to set the
with the following method in the java main:

System.setProperty("java.library.path", "./");

That didn't help. Instead i added
to the java command:

sudo java -classpath '.:classes:*:classes:/opt/pi4j/lib/*' com.epam.llpd.greenhouse.web.ServerStarter -Djava.library.path=./

But that didn't help neither.

Now i'm stuck and don't know how to add the
to the

How do i add the
to the

I asked in the Raspberry Pi StackExchange first but they thought that it's off-topic.


Try to simply rename dhtreader.so to libdhtreader.so.

Indeed when we call System.loadLibrary("foo") in java the expected name of the library is:

  • Windows: foo.dll
  • Unix/Linux: libfoo.so
  • Mac: libfoo.jnilib

Try to launch it as next:

sudo java -Djava.library.path=./lib -classpath '.:classes:*:classes:/opt/pi4j/lib/*' com.epam.llpd.greenhouse.web.ServerStarter

NB: The command above assumes that your lib is located in the lib directory that is itself located in the directory where the command has been launched.