joeferner / node-java

Bridge API to connect with existing Java APIs.
MIT License
1.87k stars 282 forks source link

Strange error with HunspellJNA #383

Open silvioOlivastri opened 7 years ago

silvioOlivastri commented 7 years ago

Hi,

I would like to call the Hunspell Java class from my NodeJs project. These are the steps that I did:

1) Clone and build the HunspellJNA project from Git 2) Open project with IntelliJ IDEA Community Edition and add a new class:

package dk.dren.hunspell;

import java.util.List;

public class SimpleHunspell {

    private Hunspell.Dictionary dictionary;

    public SimpleHunspell(String dictionaryPath, String language) {
        try {
            this.dictionary = Hunspell.getInstance("/Users/silvio/Documents/HunspellJNA/build/classes")
                    .getDictionary(dictionaryPath + "/" + language);
        } catch (Exception e) { System.out.println(e.toString()); }
    }

    public boolean misspelled(String word) {
        return this.dictionary.misspelled(word);
    }

    public List<String> suggest(String word) {
        return this.dictionary.suggest(word);
    }

    public List<String> analyze(String word) {
        return this.dictionary.analyze(word);
    }

    public List<String> stem(String word) {
        return this.dictionary.stem(word);
    }
}

3) Create the .jar file (Build -> Build Artifacts...) 4) Call the SimpleHunspell instance from the .js file:

self.hunspell = java.newInstanceSync("dk.dren.hunspell.SimpleHunspell", 
                dictionariesPath, language);

When I run my file (node file.js) from Terminal (MacOS with Java SDK 1.8), NodeJs load the .jar but goes to loop into java.newInstanceSync function (I have no errors).

When a little debug, I find that the application goes to loop into com.sun.jna.Native method.

N.B. : If I run from IntelliJ IDEA the class works well.

loretoparisi commented 7 years ago

It seems that it hangs calling the JNA loadLibrary method to load the dynamic library (that for macos it's libhunspell-darwin-x86-64.dylib)

hsl = (HunspellLibrary)Native.loadLibrary(lib.getAbsolutePath(), HunspellLibrary.class);