openvenues / jpostal

Java/JNI bindings to libpostal for for fast international street address parsing/normalization
MIT License
105 stars 42 forks source link

Can't load native library #15

Closed coachwei closed 7 years ago

coachwei commented 7 years ago

When running test java code, got the following error (I added a "main" method to the TestAddressParser class):

$  java -classpath .:../../libs/jpostal.jar com.mapzen.jpostal.TestAddressParser 
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpostal_parser in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at com.mapzen.jpostal.AddressParser.<clinit>(AddressParser.java:8)
    at com.mapzen.jpostal.TestAddressParser.testParse(TestAddressParser.java:17)
    at com.mapzen.jpostal.TestAddressParser.testParseUSAddress(TestAddressParser.java:54)
    at com.mapzen.jpostal.TestAddressParser.main(TestAddressParser.java:13)

Looks like that I need to set up the java.library.path (I checked this property. None of the directories that it points to have the libpostal library). What should I set to the java.library.path variable?

( I did built/installed libpostal and jpostal following the instructions on https://github.com/openvenues/jpostal)

albarrentine commented 7 years ago

From #3:

jpostal builds shared object files (.so on Linux, .jniLib on Mac) that also need to be on java.library.path (after you run gradle assemble the .so files can be found in src/main/jniLibs in your checkout dir). For running the tests, we set this explicitly here.

If you use gradle, there's a plugin called gradle-natives that may be helpful: https://github.com/cjstehno/coffeaelectronica/wiki/Going-Native-with-Gradle

coachwei commented 7 years ago

Thanks for the reply.

It turns out setting java system property inside Java code may not work for java.library.path variable as it is really a "read-only" variable.

Here is a link for reference purpose: How to set java.library.path within Java code

albarrentine commented 7 years ago

Right, that's why we set it in the gradle build, not in Java.