JNI Native Interface and JavaFX - NoClassDefFoundError












0















I have a bash script that launches my program using an embedded JRE. This script works:



#!/bin/bash
exec ./jre/bin/java
--module-path ./jre/jfx
--add-modules=javafx.controls,javafx.swing
--add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED
-jar hypnos.jar "$@" --base-dir="$ROOT"


I am trying to write a C++ program that uses the JNI Native Interface to replace that bash script. As you can see, they provide identical arguments to the JVM:



#include <jni.h>  

int main() {
JavaVM *jvm;
JNIEnv *env;
JavaVMInitArgs vm_args;
JavaVMOption* options = new JavaVMOption[4];
options[0].optionString = (char *)"-Djava.class.path=jre/lib/server/:./hypnos.jar";
options[1].optionString = (char *)"--module-path ./jre/jfx";
options[2].optionString = (char *)"--add-modules=javafx.controls,javafx.swing";
options[3].optionString = (char *)"--add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED";

vm_args.version = JNI_VERSION_10;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = false;
JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
delete options;

jmethodID main = NULL;
jclass cls = NULL;

cls = env->FindClass("net/joshuad/hypnos/Hypnos");
if(env->ExceptionCheck()) {
env->ExceptionDescribe();
env->ExceptionClear();
}

if (cls != NULL) {
main = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
} else {
printf("Unable to find the requested classn");
}

if (main != NULL) {
env->CallStaticVoidMethod( cls, main, " ");
} else {
printf("main method not found") ;
}

jvm->DestroyJavaVM();
return 0;
}


However, the bash script works while the C++ program gives me:
Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application with a stack trace.



I can't understand this, because it seems that the C++ program is doing the same thing that the bash script is doing.



I have an almost-identical version of this C++ program that launches a "hello world" java program that doesn't depend on javafx, and it works. So the issue seems to be the JVM created by C++ can't find JavaFX. However, I'm pointing it all the same places that the working bash script is being pointed at, so I'm not sure why it can't find JavaFX.



Any idea how to address this?










share|improve this question





























    0















    I have a bash script that launches my program using an embedded JRE. This script works:



    #!/bin/bash
    exec ./jre/bin/java
    --module-path ./jre/jfx
    --add-modules=javafx.controls,javafx.swing
    --add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED
    -jar hypnos.jar "$@" --base-dir="$ROOT"


    I am trying to write a C++ program that uses the JNI Native Interface to replace that bash script. As you can see, they provide identical arguments to the JVM:



    #include <jni.h>  

    int main() {
    JavaVM *jvm;
    JNIEnv *env;
    JavaVMInitArgs vm_args;
    JavaVMOption* options = new JavaVMOption[4];
    options[0].optionString = (char *)"-Djava.class.path=jre/lib/server/:./hypnos.jar";
    options[1].optionString = (char *)"--module-path ./jre/jfx";
    options[2].optionString = (char *)"--add-modules=javafx.controls,javafx.swing";
    options[3].optionString = (char *)"--add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED";

    vm_args.version = JNI_VERSION_10;
    vm_args.nOptions = 1;
    vm_args.options = options;
    vm_args.ignoreUnrecognized = false;
    JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
    delete options;

    jmethodID main = NULL;
    jclass cls = NULL;

    cls = env->FindClass("net/joshuad/hypnos/Hypnos");
    if(env->ExceptionCheck()) {
    env->ExceptionDescribe();
    env->ExceptionClear();
    }

    if (cls != NULL) {
    main = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
    } else {
    printf("Unable to find the requested classn");
    }

    if (main != NULL) {
    env->CallStaticVoidMethod( cls, main, " ");
    } else {
    printf("main method not found") ;
    }

    jvm->DestroyJavaVM();
    return 0;
    }


    However, the bash script works while the C++ program gives me:
    Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application with a stack trace.



    I can't understand this, because it seems that the C++ program is doing the same thing that the bash script is doing.



    I have an almost-identical version of this C++ program that launches a "hello world" java program that doesn't depend on javafx, and it works. So the issue seems to be the JVM created by C++ can't find JavaFX. However, I'm pointing it all the same places that the working bash script is being pointed at, so I'm not sure why it can't find JavaFX.



    Any idea how to address this?










    share|improve this question



























      0












      0








      0








      I have a bash script that launches my program using an embedded JRE. This script works:



      #!/bin/bash
      exec ./jre/bin/java
      --module-path ./jre/jfx
      --add-modules=javafx.controls,javafx.swing
      --add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED
      -jar hypnos.jar "$@" --base-dir="$ROOT"


      I am trying to write a C++ program that uses the JNI Native Interface to replace that bash script. As you can see, they provide identical arguments to the JVM:



      #include <jni.h>  

      int main() {
      JavaVM *jvm;
      JNIEnv *env;
      JavaVMInitArgs vm_args;
      JavaVMOption* options = new JavaVMOption[4];
      options[0].optionString = (char *)"-Djava.class.path=jre/lib/server/:./hypnos.jar";
      options[1].optionString = (char *)"--module-path ./jre/jfx";
      options[2].optionString = (char *)"--add-modules=javafx.controls,javafx.swing";
      options[3].optionString = (char *)"--add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED";

      vm_args.version = JNI_VERSION_10;
      vm_args.nOptions = 1;
      vm_args.options = options;
      vm_args.ignoreUnrecognized = false;
      JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
      delete options;

      jmethodID main = NULL;
      jclass cls = NULL;

      cls = env->FindClass("net/joshuad/hypnos/Hypnos");
      if(env->ExceptionCheck()) {
      env->ExceptionDescribe();
      env->ExceptionClear();
      }

      if (cls != NULL) {
      main = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
      } else {
      printf("Unable to find the requested classn");
      }

      if (main != NULL) {
      env->CallStaticVoidMethod( cls, main, " ");
      } else {
      printf("main method not found") ;
      }

      jvm->DestroyJavaVM();
      return 0;
      }


      However, the bash script works while the C++ program gives me:
      Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application with a stack trace.



      I can't understand this, because it seems that the C++ program is doing the same thing that the bash script is doing.



      I have an almost-identical version of this C++ program that launches a "hello world" java program that doesn't depend on javafx, and it works. So the issue seems to be the JVM created by C++ can't find JavaFX. However, I'm pointing it all the same places that the working bash script is being pointed at, so I'm not sure why it can't find JavaFX.



      Any idea how to address this?










      share|improve this question
















      I have a bash script that launches my program using an embedded JRE. This script works:



      #!/bin/bash
      exec ./jre/bin/java
      --module-path ./jre/jfx
      --add-modules=javafx.controls,javafx.swing
      --add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED
      -jar hypnos.jar "$@" --base-dir="$ROOT"


      I am trying to write a C++ program that uses the JNI Native Interface to replace that bash script. As you can see, they provide identical arguments to the JVM:



      #include <jni.h>  

      int main() {
      JavaVM *jvm;
      JNIEnv *env;
      JavaVMInitArgs vm_args;
      JavaVMOption* options = new JavaVMOption[4];
      options[0].optionString = (char *)"-Djava.class.path=jre/lib/server/:./hypnos.jar";
      options[1].optionString = (char *)"--module-path ./jre/jfx";
      options[2].optionString = (char *)"--add-modules=javafx.controls,javafx.swing";
      options[3].optionString = (char *)"--add-opens javafx.controls/javafx.scene.control=ALL-UNNAMED";

      vm_args.version = JNI_VERSION_10;
      vm_args.nOptions = 1;
      vm_args.options = options;
      vm_args.ignoreUnrecognized = false;
      JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
      delete options;

      jmethodID main = NULL;
      jclass cls = NULL;

      cls = env->FindClass("net/joshuad/hypnos/Hypnos");
      if(env->ExceptionCheck()) {
      env->ExceptionDescribe();
      env->ExceptionClear();
      }

      if (cls != NULL) {
      main = env->GetStaticMethodID(cls, "main", "([Ljava/lang/String;)V");
      } else {
      printf("Unable to find the requested classn");
      }

      if (main != NULL) {
      env->CallStaticVoidMethod( cls, main, " ");
      } else {
      printf("main method not found") ;
      }

      jvm->DestroyJavaVM();
      return 0;
      }


      However, the bash script works while the C++ program gives me:
      Exception in thread "main" java.lang.NoClassDefFoundError: javafx/application/Application with a stack trace.



      I can't understand this, because it seems that the C++ program is doing the same thing that the bash script is doing.



      I have an almost-identical version of this C++ program that launches a "hello world" java program that doesn't depend on javafx, and it works. So the issue seems to be the JVM created by C++ can't find JavaFX. However, I'm pointing it all the same places that the working bash script is being pointed at, so I'm not sure why it can't find JavaFX.



      Any idea how to address this?







      java jni jnienv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 11:15







      JoshuaD

















      asked Nov 24 '18 at 11:10









      JoshuaDJoshuaD

      1,20531835




      1,20531835
























          1 Answer
          1






          active

          oldest

          votes


















          1














          This



          vm_args.nOptions = 1;


          needs to be



          vm_args.nOptions = 4;





          share|improve this answer
























          • Thanks. I'll try that out tonight. Not used to working in C so I missed that.

            – JoshuaD
            Nov 26 '18 at 20:52






          • 1





            I work in Java a lot, coming back to C/C++ is always a bit jarring.

            – Wheezil
            Nov 28 '18 at 0:00











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457524%2fjni-native-interface-and-javafx-noclassdeffounderror%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          This



          vm_args.nOptions = 1;


          needs to be



          vm_args.nOptions = 4;





          share|improve this answer
























          • Thanks. I'll try that out tonight. Not used to working in C so I missed that.

            – JoshuaD
            Nov 26 '18 at 20:52






          • 1





            I work in Java a lot, coming back to C/C++ is always a bit jarring.

            – Wheezil
            Nov 28 '18 at 0:00
















          1














          This



          vm_args.nOptions = 1;


          needs to be



          vm_args.nOptions = 4;





          share|improve this answer
























          • Thanks. I'll try that out tonight. Not used to working in C so I missed that.

            – JoshuaD
            Nov 26 '18 at 20:52






          • 1





            I work in Java a lot, coming back to C/C++ is always a bit jarring.

            – Wheezil
            Nov 28 '18 at 0:00














          1












          1








          1







          This



          vm_args.nOptions = 1;


          needs to be



          vm_args.nOptions = 4;





          share|improve this answer













          This



          vm_args.nOptions = 1;


          needs to be



          vm_args.nOptions = 4;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 26 '18 at 15:08









          WheezilWheezil

          1,91211129




          1,91211129













          • Thanks. I'll try that out tonight. Not used to working in C so I missed that.

            – JoshuaD
            Nov 26 '18 at 20:52






          • 1





            I work in Java a lot, coming back to C/C++ is always a bit jarring.

            – Wheezil
            Nov 28 '18 at 0:00



















          • Thanks. I'll try that out tonight. Not used to working in C so I missed that.

            – JoshuaD
            Nov 26 '18 at 20:52






          • 1





            I work in Java a lot, coming back to C/C++ is always a bit jarring.

            – Wheezil
            Nov 28 '18 at 0:00

















          Thanks. I'll try that out tonight. Not used to working in C so I missed that.

          – JoshuaD
          Nov 26 '18 at 20:52





          Thanks. I'll try that out tonight. Not used to working in C so I missed that.

          – JoshuaD
          Nov 26 '18 at 20:52




          1




          1





          I work in Java a lot, coming back to C/C++ is always a bit jarring.

          – Wheezil
          Nov 28 '18 at 0:00





          I work in Java a lot, coming back to C/C++ is always a bit jarring.

          – Wheezil
          Nov 28 '18 at 0:00




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457524%2fjni-native-interface-and-javafx-noclassdeffounderror%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin