Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Loading DLL from file not PATH

Loading DLL from file not PATH

Scheduled Pinned Locked Moved C / C++ / MFC
helpjavac++comdebugging
28 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Victor Nijegorodov

    Well, has it worked when you added the location of jvm.dll to PATH?

    V Offline
    V Offline
    Valentinor
    wrote on last edited by
    #5

    Yeah, that was the first thing I tried. I even tried it's Released version (copy in another location .exe and the required .class file) and that was working fine if I had it in PATH, but same problem as soon as I removed it from there and added the dll file.

    1 Reply Last reply
    0
    • V Valentinor

      I was reading this turorial on how to use Java in your C++ project, and at one step it says to add the location of jvm.dll to PATH. Well that is fine for developing purpose, but not for a released project. So instead of that I tried the second part, to add it manually to Debug/Release folder and remove the location from PATH, but unfortunately I'm getting the following error:

      Error occurred during initialization of VM
      Failed setting boot class path.

      What I'm I doing wrong, and how to fix the problem?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      You should not do this; Java uses other items in its run-time library. Any client wishing to run your application will need to install Java before they can use it. And it is quite possible that if you install the dll yourself you will be breaching Oracle's licencing conditions.

      V 1 Reply Last reply
      0
      • L Lost User

        You should not do this; Java uses other items in its run-time library. Any client wishing to run your application will need to install Java before they can use it. And it is quite possible that if you install the dll yourself you will be breaching Oracle's licencing conditions.

        V Offline
        V Offline
        Valentinor
        wrote on last edited by
        #7

        I thought that is the problem but then what is the solution for this? Having the user to install Java isn't a problem, but even if it is installed, I still need to add something in Visual Studio to know where to look for jvm.dll as it is the case with /include and /include/win32, or else it will give me an error with "jvm.dll not found".

        V L 2 Replies Last reply
        0
        • V Valentinor

          I thought that is the problem but then what is the solution for this? Having the user to install Java isn't a problem, but even if it is installed, I still need to add something in Visual Studio to know where to look for jvm.dll as it is the case with /include and /include/win32, or else it will give me an error with "jvm.dll not found".

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #8

          You have to read the documentation about what and where is to be written while installing the Java. Perhaps you will also need to check the registry to find out where Java installer stores the path you need for your application to work properly.

          1 Reply Last reply
          0
          • V Valentinor

            I thought that is the problem but then what is the solution for this? Having the user to install Java isn't a problem, but even if it is installed, I still need to add something in Visual Studio to know where to look for jvm.dll as it is the case with /include and /include/win32, or else it will give me an error with "jvm.dll not found".

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            If the customer correctly installs the Java runtime then it will set the PATH variable with the correct details. Your code should then run correctly. I have done a test on my system and that is all that is needed as far as I can tell. The /include and /include/win32 files are only required to build your application, not to run it. The customer just needs the correct C/C++ libraries installed - Latest supported Visual C++ Redistributable downloads | Microsoft Docs[^].

            1 Reply Last reply
            0
            • V Valentinor

              I was reading this turorial on how to use Java in your C++ project, and at one step it says to add the location of jvm.dll to PATH. Well that is fine for developing purpose, but not for a released project. So instead of that I tried the second part, to add it manually to Debug/Release folder and remove the location from PATH, but unfortunately I'm getting the following error:

              Error occurred during initialization of VM
              Failed setting boot class path.

              What I'm I doing wrong, and how to fix the problem?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #10

              For C++ projects, I think in some versions of Visual Studio the 'current directory' is actually the $(SolutionDir) or maybe $(ProjectDir) when you run from the IDE. Using a search engine[^] you will find that the JVM is loaded with LOAD_WITH_ALTERED_SEARCH_PATH Have a look here: Dynamic-Link Library Search Order - Win32 apps | Microsoft Docs[^] Scroll down to the documentation about LOAD_WITH_ALTERED_SEARCH_PATH This flag means that the path containing the executable will never be checked. The 'current directory' is checked. Which I believe is $(SolutionDir) or maybe $(ProjectDir) when you launch from Visual Studio.

              1 Reply Last reply
              0
              • V Valentinor

                I was reading this turorial on how to use Java in your C++ project, and at one step it says to add the location of jvm.dll to PATH. Well that is fine for developing purpose, but not for a released project. So instead of that I tried the second part, to add it manually to Debug/Release folder and remove the location from PATH, but unfortunately I'm getting the following error:

                Error occurred during initialization of VM
                Failed setting boot class path.

                What I'm I doing wrong, and how to fix the problem?

                V Offline
                V Offline
                Valentinor
                wrote on last edited by
                #11

                I wanted to try Java 1.8.0_202 to test some other stuff, but after changing in PATH the location for jvm.dll for this version, and also in Visual Studio the location for the folders /include,/include/win32, and /jdk1.8.0_202/lib for jvm.lib, now I'm getting that it can't find the class file. I tried the following (solution name "Article-JNI-1", project name "Example3", class file name "MyTest.class"): - Leaving the class in "\Article-JNI-1\Exemple3" folder; - Moving it to "\Article-JNI-1"; - Moving it to "\Article-JNI-1\x64\Debug"; - Changing code to options[0].optionString = "-Djava.class.path=D:\\"; and moving the class there. In all those situations I'm getting the same thing, the error from line 58:

                cerr << "ERROR: class not found !";

                While working with jdk-17.0.1 it was working fine when running from Visual Studio. What am I missing/doing wrong?

                L 1 Reply Last reply
                0
                • V Valentinor

                  I wanted to try Java 1.8.0_202 to test some other stuff, but after changing in PATH the location for jvm.dll for this version, and also in Visual Studio the location for the folders /include,/include/win32, and /jdk1.8.0_202/lib for jvm.lib, now I'm getting that it can't find the class file. I tried the following (solution name "Article-JNI-1", project name "Example3", class file name "MyTest.class"): - Leaving the class in "\Article-JNI-1\Exemple3" folder; - Moving it to "\Article-JNI-1"; - Moving it to "\Article-JNI-1\x64\Debug"; - Changing code to options[0].optionString = "-Djava.class.path=D:\\"; and moving the class there. In all those situations I'm getting the same thing, the error from line 58:

                  cerr << "ERROR: class not found !";

                  While working with jdk-17.0.1 it was working fine when running from Visual Studio. What am I missing/doing wrong?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #12

                  This is the code I use to load a class from C++:

                  //
                  // A function to start the Java VM and initialise the JNI interface
                  //
                  JNIEnv* createJVM(
                  JavaVM* jvm,
                  std::string strcwd
                  )
                  {
                  // tell the JVM where to find the class
                  JavaVMOption options{};
                  std::stringstream ssoptions;
                  ssoptions << "-Djava.class.path=";
                  // the class files are in the current directory.
                  // change this if yours are somewhere else
                  ssoptions << strcwd;
                  std::string stropts = ssoptions.str();
                  options.optionString = const_cast(stropts.c_str());

                  JavaVMInitArgs  vm\_args; // JDK/JRE 6 VM initialization arguments
                  vm\_args.version = JNI\_VERSION\_1\_8;
                  vm\_args.nOptions = 1;
                  vm\_args.ignoreUnrecognized = false;
                  vm\_args.options = &options;
                  
                  JNIEnv\* env;            // pointer to native method interface
                  // this should load the jvm.dll based on the PATH variable
                  jint res = JNI\_CreateJavaVM(&jvm, (void\*\*)&env, &vm\_args);
                  if (res != 0)
                  {
                      std::cout << "C++: JNI\_CreateJavaVM returned: " << res << std::endl;
                  }
                  
                  return env;
                  

                  }

                  The caller then uses the env pointer to access the remaining JNI functions.

                  V 1 Reply Last reply
                  0
                  • L Lost User

                    This is the code I use to load a class from C++:

                    //
                    // A function to start the Java VM and initialise the JNI interface
                    //
                    JNIEnv* createJVM(
                    JavaVM* jvm,
                    std::string strcwd
                    )
                    {
                    // tell the JVM where to find the class
                    JavaVMOption options{};
                    std::stringstream ssoptions;
                    ssoptions << "-Djava.class.path=";
                    // the class files are in the current directory.
                    // change this if yours are somewhere else
                    ssoptions << strcwd;
                    std::string stropts = ssoptions.str();
                    options.optionString = const_cast(stropts.c_str());

                    JavaVMInitArgs  vm\_args; // JDK/JRE 6 VM initialization arguments
                    vm\_args.version = JNI\_VERSION\_1\_8;
                    vm\_args.nOptions = 1;
                    vm\_args.ignoreUnrecognized = false;
                    vm\_args.options = &options;
                    
                    JNIEnv\* env;            // pointer to native method interface
                    // this should load the jvm.dll based on the PATH variable
                    jint res = JNI\_CreateJavaVM(&jvm, (void\*\*)&env, &vm\_args);
                    if (res != 0)
                    {
                        std::cout << "C++: JNI\_CreateJavaVM returned: " << res << std::endl;
                    }
                    
                    return env;
                    

                    }

                    The caller then uses the env pointer to access the remaining JNI functions.

                    V Offline
                    V Offline
                    Valentinor
                    wrote on last edited by
                    #13

                    I added your function but I have the same result. And so I decided to do a little bit of testing. In Visual Studio I left the locations for jdk1.8.0_202 in properties, but I changed in PATH the location for jvm.dll. IF I'm using the PATH for jdk-17.0.1 it is working fine, but as soon as I change it to jdk1.8.0_202 it doesn't find the class anymore.

                    L 1 Reply Last reply
                    0
                    • V Valentinor

                      I added your function but I have the same result. And so I decided to do a little bit of testing. In Visual Studio I left the locations for jdk1.8.0_202 in properties, but I changed in PATH the location for jvm.dll. IF I'm using the PATH for jdk-17.0.1 it is working fine, but as soon as I change it to jdk1.8.0_202 it doesn't find the class anymore.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #14

                      There should be no difference between the two. But Without access to your system it is impossible to guess what might be the problem.

                      V 1 Reply Last reply
                      0
                      • L Lost User

                        There should be no difference between the two. But Without access to your system it is impossible to guess what might be the problem.

                        V Offline
                        V Offline
                        Valentinor
                        wrote on last edited by
                        #15

                        I just created 2 new VM's (Windows 10 x64), in one I installed Java SE 8 with Visual Studio, and I was getting the same thing, class not found, then I installed Java SE 17 and just like on host, no problem it is running fine. Then on the second machine I installed Java from oracle ^, which the user would do, and copied the working executable (with no errors) to it (after installing needed redistributable of curse) but I'm getting "jvm.dll" not found error.

                        L 1 Reply Last reply
                        0
                        • V Valentinor

                          I just created 2 new VM's (Windows 10 x64), in one I installed Java SE 8 with Visual Studio, and I was getting the same thing, class not found, then I installed Java SE 17 and just like on host, no problem it is running fine. Then on the second machine I installed Java from oracle ^, which the user would do, and copied the working executable (with no errors) to it (after installing needed redistributable of curse) but I'm getting "jvm.dll" not found error.

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #16

                          I just installed the 1.8 version of Java and rebuilt my project and it works fine. Have you checked that you are not trying to mix x86 and x64 code? Version 17 is x64 only, but 1.8 offers both. So if you have the x86 version installed that could be the problem.

                          V 1 Reply Last reply
                          0
                          • V Valentinor

                            Yeah, to be sure there isn't a problem with the installation, I even just uninstalled everything Java related, and reinstalled them. I don't even have a folder in "Program files (x86)", and in x64 I have these only 17 and 1.8 (and what I'm working on right now it is for x64 only anyway): https://i.ibb.co/X3xcDcf/image.png[^] When I have in PATH location from 1.8: https://i.ibb.co/K0vzM4J/image.png[^] And when I have in PATH location from 17: https://i.ibb.co/d23HNTv/image.png[^] It is the project from that tutorial with unmodified files. I even did some Java socket call tests from C++ and they worked fine with 17. That is kinda the main reason I need this Java/C++ combination for, as I already have some systems made in Java that this new project (made in Unreal Engine which is C++) will relay on.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #17

                            Make sure that you build the C++ part and the Java part with the same version of Java, they may not be fully compatible across different versions. Also, rather than using pictures to post simple text information, please use copy and paste and add it to your question.

                            V 1 Reply Last reply
                            0
                            • L Lost User

                              Make sure that you build the C++ part and the Java part with the same version of Java, they may not be fully compatible across different versions. Also, rather than using pictures to post simple text information, please use copy and paste and add it to your question.

                              V Offline
                              V Offline
                              Valentinor
                              wrote on last edited by
                              #18

                              Yeah that was the problem for saying that it can't find the class, I just added target and source and now it is working, but the second part is still a problem. I copied the released executable and the class file to a freshly created VM with only Java and redistributable installed and I'm getting the same error:

                              Example3.exe - System Error

                              The code execution cannot proceed because jvm.dll was not found. Reinstalling the program may fix this problem.

                              Off topic: They should add an image preview, because those are really useful.

                              L 1 Reply Last reply
                              0
                              • L Lost User

                                I just installed the 1.8 version of Java and rebuilt my project and it works fine. Have you checked that you are not trying to mix x86 and x64 code? Version 17 is x64 only, but 1.8 offers both. So if you have the x86 version installed that could be the problem.

                                V Offline
                                V Offline
                                Valentinor
                                wrote on last edited by
                                #19

                                Yeah, to be sure there isn't a problem with the installation, I even just uninstalled everything Java related, and reinstalled them. I don't even have a folder in "Program files (x86)", and in x64 I have these only 17 and 1.8 (and what I'm working on right now it is for x64 only anyway): https://i.ibb.co/X3xcDcf/image.png[^] When I have in PATH location from 1.8: https://i.ibb.co/K0vzM4J/image.png[^] And when I have in PATH location from 17: https://i.ibb.co/d23HNTv/image.png[^] It is the project from that tutorial with unmodified files. I even did some Java socket call tests from C++ and they worked fine with 17. That is kinda the main reason I need this Java/C++ combination for, as I already have some systems made in Java that this new project (made in Unreal Engine which is C++) will relay on.

                                L 1 Reply Last reply
                                0
                                • V Valentinor

                                  Yeah that was the problem for saying that it can't find the class, I just added target and source and now it is working, but the second part is still a problem. I copied the released executable and the class file to a freshly created VM with only Java and redistributable installed and I'm getting the same error:

                                  Example3.exe - System Error

                                  The code execution cannot proceed because jvm.dll was not found. Reinstalling the program may fix this problem.

                                  Off topic: They should add an image preview, because those are really useful.

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #20

                                  Valentinor wrote:

                                  The code execution cannot proceed because jvm.dll was not found.

                                  I think I have answered that more than once.

                                  Valentinor wrote:

                                  They should add an image preview

                                  This has been rejected a number of times as it would be open to abuse by spammers.

                                  V 1 Reply Last reply
                                  0
                                  • L Lost User

                                    Valentinor wrote:

                                    The code execution cannot proceed because jvm.dll was not found.

                                    I think I have answered that more than once.

                                    Valentinor wrote:

                                    They should add an image preview

                                    This has been rejected a number of times as it would be open to abuse by spammers.

                                    V Offline
                                    V Offline
                                    Valentinor
                                    wrote on last edited by
                                    #21

                                    Richard MacCutchan wrote:

                                    If the customer correctly installs the Java runtime then it will set the PATH variable with the correct details. Your code should then run correctly. I have done a test on my system and that is all that is needed as far as I can tell.

                                    You did said this, and I've done it, even on 2 new separate VM's, installed Java and needed redistributable and on both I get the same error.

                                    L 1 Reply Last reply
                                    0
                                    • V Valentinor

                                      Richard MacCutchan wrote:

                                      If the customer correctly installs the Java runtime then it will set the PATH variable with the correct details. Your code should then run correctly. I have done a test on my system and that is all that is needed as far as I can tell.

                                      You did said this, and I've done it, even on 2 new separate VM's, installed Java and needed redistributable and on both I get the same error.

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #22

                                      So you keep saying. But I cannot see what is happening on your system. I have tried multiple tests of this issue with Java versions 1.8, 14 and 17 and cannot recreate the problem you are having.

                                      V 1 Reply Last reply
                                      0
                                      • L Lost User

                                        So you keep saying. But I cannot see what is happening on your system. I have tried multiple tests of this issue with Java versions 1.8, 14 and 17 and cannot recreate the problem you are having.

                                        V Offline
                                        V Offline
                                        Valentinor
                                        wrote on last edited by
                                        #23

                                        unknown 2022 06 16 11 59 - YouTube[^] Here is a video, first run is on host where I have jdk, Visual Studio..., and second is on VM.

                                        L 1 Reply Last reply
                                        0
                                        • V Valentinor

                                          unknown 2022 06 16 11 59 - YouTube[^] Here is a video, first run is on host where I have jdk, Visual Studio..., and second is on VM.

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #24

                                          I owe you an apology. I do not have a VM to run this on so my reinstalls of Java were missing something that I had set up in the past. The jvm.dll is not in the bin directory of the JRE installation, but in a subdirectory named server. This was in my PATH variable and was not removed when I uninstalled one of the Java versions. So you need to add that location to the PATH variable manually. Sorry again for the confusion.

                                          V 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups