Using JNI to call Java functions which have library dependencies

210 Views Asked by At

For my project, I'm using C++ to call a Java Class which uses NLP Natty Date Parser Library, using JNI.

Before using the Library, when I worked with a simple Java class without any library dependencies to send a string to C++ there wasn't any problem. But once I included the respective library to parse the string, I'm not getting the result that I want. I suspect that the Java class is unable to make calls to the library.

This is an example of the function I'm calling in Java

import com.joestelmach.natty.*;

public static boolean isValidCommand(String command){
    List<DateGroup> sample;
    Parser parser = new Parser(TimeZone.getDefault());
    sample = parser.parse(command);
    if(sample.get(LOCATION_OF_DATE).getDates().size() > MAX_LIMIT)
        return TOO_MANY_DATES;
    return true;
}

This is the function in C++ which calls the aforementioned Java function.

bool Wrapper::isValidCommand(string command){
if(_cls != 0) {
    jmethodID mid = _env->GetStaticMethodID(_cls,"isValidCommand","(Ljava/lang/String;)Z");
    if(mid != 0){
        jboolean data = _env->CallStaticBooleanMethod(_cls,mid,_env->NewStringUTF(command.c_str()));
        return data;
    }
}
return false;
}

I'm unsure as to how I can link the library dependencies of the Java class I'm calling. Appreciate if anyone can help. Thanks in advance.

0

There are 0 best solutions below