How to call Jar files from Visual C++
-
Nikhil Trivedi wrote:
For one of my projects I need to call jar files from the visual c++ application
If you just want to unpack the jar file then use
ShellExecute
. Prepare a command string like"Cmd.exe YourJarFilePath.jar -Arg1 - Arg2"
, then pass it toShellExecute
.
Nibu thomas A Developer Programming tips[^] My site[^]
This might be a bit helpful. Can you send me a sample code say I want to call a jar file at location C:\psae.jar with the parameter "world" then the syntax from command prompt is : java -jar C:\psae.jar world How the command string should look like for this one ? Thanks for your reply Nikhs Nikhil Trivedi
-
I believe you need to look into JNI: http://www.codeproject.com/java/jnibasics1.asp[^]
"We make a living by what we get, we make a life by what we give." --Winston Churchill
I dont wanna call c++ function from java but wanna call jar file from visual c++. BTW, thank you for your reply. Nikhs Nikhil Trivedi
-
This might be a bit helpful. Can you send me a sample code say I want to call a jar file at location C:\psae.jar with the parameter "world" then the syntax from command prompt is : java -jar C:\psae.jar world How the command string should look like for this one ? Thanks for your reply Nikhs Nikhil Trivedi
Nikhil Trivedi wrote:
java -jar C:\psae.jar world
So in this case the command will be the same... Look up
ShellExecute
inMSDN
. ThelpFile
parameter should be "java.exe" andlpParameters
should be "-jar C:\psae.jar world".
Nibu thomas A Developer Programming tips[^] My site[^]
-
Nikhil Trivedi wrote:
java -jar C:\psae.jar world
So in this case the command will be the same... Look up
ShellExecute
inMSDN
. ThelpFile
parameter should be "java.exe" andlpParameters
should be "-jar C:\psae.jar world".
Nibu thomas A Developer Programming tips[^] My site[^]
Thanks Dear friend. It really will help a lot. Nikhs Nikhil Trivedi
-
Thanks Dear friend. It really will help a lot. Nikhs Nikhil Trivedi
Nikhil Trivedi wrote:
It really will help a lot.
Did it work. :)
Nibu thomas A Developer Programming tips[^] My site[^]
-
Nikhil Trivedi wrote:
It really will help a lot.
Did it work. :)
Nibu thomas A Developer Programming tips[^] My site[^]
It didn't work. When I use debuger, it shows me the return value of the shellexecute as 2 and the value for getlasterror is the same. I dont knokw how to deal this ? I am using the following code snippet :
HINSTANCE hInst; hInst= ShellExecute(NULL,reinterpret_cast("open"),reinterpret_cast("C:\j2sdk1.4.2_12\bin\java.exe"),reinterpret_cast("-jar C:\psae.jar WORLD"),NULL,SW_SHOWMAXIMIZED);
and even try with this one :hInst= ShellExecute(NULL,reinterpret_cast("java"),reinterpret_cast("C:\j2sdk1.4.2_12\bin\java.exe"),reinterpret_cast("-jar C:\psae.jar WORLD"),NULL,SW_SHOWMAXIMIZED);
both shows the same error. Error no. 2. -
It didn't work. When I use debuger, it shows me the return value of the shellexecute as 2 and the value for getlasterror is the same. I dont knokw how to deal this ? I am using the following code snippet :
HINSTANCE hInst; hInst= ShellExecute(NULL,reinterpret_cast("open"),reinterpret_cast("C:\j2sdk1.4.2_12\bin\java.exe"),reinterpret_cast("-jar C:\psae.jar WORLD"),NULL,SW_SHOWMAXIMIZED);
and even try with this one :hInst= ShellExecute(NULL,reinterpret_cast("java"),reinterpret_cast("C:\j2sdk1.4.2_12\bin\java.exe"),reinterpret_cast("-jar C:\psae.jar WORLD"),NULL,SW_SHOWMAXIMIZED);
both shows the same error. Error no. 2.Why all of the
reinterpret_cast()
code? Aren't you forgetting to use double backslashes in your string literals?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Why all of the
reinterpret_cast()
code? Aren't you forgetting to use double backslashes in your string literals?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
I didn't get the point you raised. Can you explain me that with some example ? Thanks for your reply. Nikhs Nikhil Trivedi
-
I didn't get the point you raised. Can you explain me that with some example ? Thanks for your reply. Nikhs Nikhil Trivedi
What's not to understand?
HINSTANCE hInst = ShellExecute(NULL, "open", "C:\\j2sdk1.4.2_12\\bin\\java.exe", "-jar C:\\psae.jar WORLD", NULL, SW_SHOWMAXIMIZED);
If you are using Unicode, just precede the string literals with an
L
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
What's not to understand?
HINSTANCE hInst = ShellExecute(NULL, "open", "C:\\j2sdk1.4.2_12\\bin\\java.exe", "-jar C:\\psae.jar WORLD", NULL, SW_SHOWMAXIMIZED);
If you are using Unicode, just precede the string literals with an
L
.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Got it. Thanks to remind me about that. Can you help me how can i send a java command to command prompt through visual c++. I want to unpack a jar file which can be done from command prompt by passing a command like : java -jar C:\myfile.jar para Appreciate your advice. Nikhs Nikhil Trivedi
-
Got it. Thanks to remind me about that. Can you help me how can i send a java command to command prompt through visual c++. I want to unpack a jar file which can be done from command prompt by passing a command like : java -jar C:\myfile.jar para Appreciate your advice. Nikhs Nikhil Trivedi
I got the jar files executed from visual c++. But If I want the return value of the jar file into the visual C++ application, how can I get it ? Does anyone know about it then please help me. Appriciate your help. Nikhs Nikhil Trivedi
-
Nikhil Trivedi wrote:
It really will help a lot.
Did it work. :)
Nibu thomas A Developer Programming tips[^] My site[^]
Hello dear friend, It worked. Now I want to call a function from the jar file and want its return value in the calling visual c++ application. Do you know how to do this ? Any help or advice is appriciated. Nikhs Nikhil Trivedi
-
I got the jar files executed from visual c++. But If I want the return value of the jar file into the visual C++ application, how can I get it ? Does anyone know about it then please help me. Appriciate your help. Nikhs Nikhil Trivedi
Nikhil Trivedi wrote:
But If I want the return value of the jar file into the visual C++ application, how can I get it ? Does anyone know about it then please help me.
See here and here. Using these examples, you should be able to get the output of java.exe.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne