openvenues / jpostal

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

no jpostal_parser in java.library.path #41

Open mareebsiddiqui opened 2 years ago

mareebsiddiqui commented 2 years ago

I have been trying to load jpostal into an existing maven project. To do this, I added a jpostal folder with the following files at the root directory of my project:

  1. libjpostal_expander.a
  2. libjpostal_expander.jnilib
  3. libjpostal_expander.la
  4. libjpostal_parser.a
  5. libjpostal_parser.jnilib
  6. libjpostal_parser.la

This is my main class:

public class Main {
    public static void main(String[] args) {
        System.loadLibrary("jpostal_parser");
    }
}

Before running my class, I set -Djava.library.path=./jpostal.

This is the output:

/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home/bin/java -Djava.library.path=./jpostal -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=56917:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/areeb.siddiqui/Documents/Projects/jpostalLibTest/target/classes Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpostal_parser in java.library.path: [./jpostal]
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2662)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
    at java.base/java.lang.System.loadLibrary(System.java:1871)
    at Main.main(Main.java:3)

Process finished with exit code 1

Compute Details: Chip: MacBook Pro (M1 Pro chip) OS: macOS Monterey (v12.1)

Things already tried:

  1. Copy jpostal files into another project and try and load it there. Doesn't work.
  2. I tried using System.load() instead of loadLibrary by giving it the absolute path of the libjpostal_parser.jnilib. It gave me an error that it can not find the file.
  3. I tried playing with changing the working directory and java.library.path to reference the library in other ways. Didn't work.
  4. Clone jpostal locally and build it on my computer then copy the resulting src/main/jniLibs content into /jpostal in my project. Building it was a bit tricky. I had to comment out AX_JNI_INCLUDE_DIR in configure.ac because it kept trying to find JDK header in locations where it isnt as I have installed oracle jdk and the macro fails to look inside /Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home/include. Then removed the loop that was creating CFLAGS variable and replace that with the following lines:
    CFLAGS="-I/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home/include"
    CFLAGS="$CFLAGS -I/Library/Java/JavaVirtualMachines/jdk-11.0.15.jdk/Contents/Home/include/darwin"

    Didn't work.

I am out of ideas on what could possibly be wrong. How to fix this?