0

i have an app built using micronaut, jni & mqtt. To create a c/c++ header file to communicate with hardware, how to run or create .h file dynamically while its running on the Raspberry Pi.

i use javac -cp "required_dependencyJAR_ABC.jar" MyNativeFile.java in command line.

Question is while running the micronaut app how to invoke this utility for header generation.

user9990
  • 93
  • 1
  • 1
  • 6
  • 1
    What do you mean 'dynamically'? `javac -h` just generates header files, so where would you get the implementation from? And that is before we get the discussion of whether you are using native mode, because that does not support dynamic class loading at all. – Botje Jun 20 '22 at 07:17
  • "Question is while running the micronaut app how to invoke this utility for header generation." - FYI... It isn't clear what role Micronaut could play in invoking the utility. Micronaut isn't going to be involved in the fact that you are invoking a native method. – Jeff Scott Brown Jun 20 '22 at 18:27
  • This isn't exactly a duplicate, but basically the same as https://stackoverflow.com/questions/72641472/how-to-integrate-micronaut-graalvm-with-jni. – Jeff Scott Brown Jun 22 '22 at 19:03
  • my question is like : i have an micronaut app running which consumes message from MQTT. based on the request now it has to call a native method in cpp. i will have only 1 native method. – user9990 Jun 24 '22 at 06:12
  • It isn't clear to me what in particular you are looking for help with but if you are trying to learn the basics of how to invoke native methods, Baeldung's intro at https://www.baeldung.com/jni is a good starting point. – Jeff Scott Brown Jun 24 '22 at 13:12
  • This method Listnes and get request from MQTT: `public void subscribeToMqtt(Message message) { executor.cppMethod(); } ` `public class TestExecutor { static { System.loadLibrary("native"); } public native String cppMethod(); }` cpp: `JNIEXPORT jstring JNICALL methodNAME (JNIEnv* env, jobject thisObject) { printf("START PI TEST! \n"); return env->NewStringUTF("Hello from C++ !!"); } ` – user9990 Jun 25 '22 at 02:07
  • @user9990 I pasted that at https://gist.github.com/jeffbrown/73835f3f4b2548bab2e7693a0e0349f4 to make it easier to view. – Jeff Scott Brown Jun 27 '22 at 12:30

0 Answers0