I am trying to make a Java program, but I want it to be opened by C++.
I have been this using in C++
system("java -jar MMQ4.jar");
But it requires the users to add C:\\Program Files\\Java\\jre7\\bin\\ to their PATH environmental variable
So, is their another way to run a Java program using C++?
running java files does NOT require the user to add something to environment variables, thats simply wrong as the Java-installer already does that automatically.
If you cant run the the java-binary without adding something to the environment your JRE is faulty and you need to reinstall. Please dont believe everything you read on internet forums, this statement is a really old myth, it was true about 5 years ago for JDK-releases but everyting after that .... not so much
One solution, not nice in my opinion is:
system("export LD_LIBRARY_PATH=\"<java_path>\" && java -jar MMQ4.jar");
This solution is valid for unix so
For windows, take a look here .
By the way, if I understand what are your intentions, you should use:
fork
exec
wait
rather than system.
const int pid = fork();
execv("java", "-jar MMQ4.jar"");
In this way you have a reference to PID's process and kill it when you want.
Have you tried using the -classpath
option to the Java interpreter. It's been some time since I've used Java, but in the past, that would have worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.