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.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?
//// A function to start the Java VM and initialise the JNI interface//
// tell the JVM where to find the class
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<char*>(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;
The caller then uses the env pointer to access the remaining JNI functions.
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.
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.
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.
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.
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.
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 ErrorThe 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.
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.
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.
The thing is that when Java is installed it doesn't add some kind of dynamic link in PATH to where jvm.dll is located, well it doesn't add one at all.
Yes, if I'm compiling the class with 1.8 and then on VM I can manually add in PATH the server folder, but here is a problem, the user should not go though this process of opening variables and find PATH to add it there.
A solution would be that when the app is opened, it would check if Java in installed, if it is not, then the user would be prompted to download it, or I have to search and see if you can legally distribute JavaSetup8uxxx.exe file and if you can the app would automatically run the file and the user would go though the process of installing Java. After Java is installed by either way then the app will search what version is installed to know what location to add in PATH, which it would do after knowing that. At this point the app will run fine.
BUT then you run into another problem, if the user updates Java then the location will change for jvm.dll, so you would have to add another variable to PATH with the new location for it, and remove the old one.
Adding a variable to PATH shouldn't be a problem, as Java and other programs do it too, I'll just have to see how that is done from C++ code.
If this is actually the only way to do it, then I guess I can do it this way, but having another solution that wouldn't involve adding variables to PATH would have been better.
I have tried a couple of ideas, and looked again at the documentation, but I cannot find a simple answer. It would appear that there is no simple method of installing this on a user's system, other than what you have already discovered.
That does not make sense. The data pointed to by the MEASUREITEMSTRUCT is what you have set when you create the control. However, whether it is ANSI or Unicode does not matter, as the actual display dimensions will be the same.
An instructor has asked you to write a program that can tell him if his students have passed or
failed his course. He has a file that contains the following information:
• first name
• last name
• five quiz grades
• the midterm exam grade
• the final exam grade
Your program must read these values into variables then use those variables to calculate the
final average and finally display that average to the screen.
1. All input comes from a file – grades.txt. You may NOT ask for input from the professor. This
file is posted on Canvas for your program to use.
2. Remember: Your program must calculate the final average including those quizzes. All the
quizzes averaged together count as much as a test. So, to calculate the final, you need to
calculate the quiz average first, then average the midterm + final + quiz average.
3. Display the student’s last name first, comma, space and first name. Follow that with the final
average as a whole number, rounded up
The file contains one line of data in the following order:
firstName lastName q1 q2 q3 q4 q5 midterm final
Remember, data must be read in sequentially! This means that the first name variable must be
initialized before the last name or the quiz one and etc.
using namespace std;
/* run this prgram using the console pauser or add your own getch, system('pause") or input look */
int main(int argc, char** argv)
int q1, q2, q3, q4, q5, midterm, final;
I need to use an input file to find that course average. The course average is a mathematical expression involved in quiz average, midterm grade, and final grade. I am trying to get the program to read what is in the file. There is the first name, last name, and 7 numbers. I need to use these values in the program to get an average for the class.
How are your results different from what is expected? Also, showing the files exact contents would be helpful.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
Last Visit: 31-Dec-99 19:00 Last Update: 2-Dec-22 0:19