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. How to call Jar files from Visual C++

How to call Jar files from Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonhelptutorial
16 Posts 4 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.
  • N Nikhil Trivedi

    Hello friends, For one of my projects I need to call jar files from the visual c++ application. Can anyone tell me how this can be done. If sample code is there then it will help a lot or the API if there is any. Thanks for your reply. Nikhs Nikhil Trivedi

    G Offline
    G Offline
    George L Jackson
    wrote on last edited by
    #2

    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

    N 1 Reply Last reply
    0
    • N Nikhil Trivedi

      Hello friends, For one of my projects I need to call jar files from the visual c++ application. Can anyone tell me how this can be done. If sample code is there then it will help a lot or the API if there is any. Thanks for your reply. Nikhs Nikhil Trivedi

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #3

      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 to ShellExecute.


      Nibu thomas A Developer Programming tips[^]  My site[^]

      N 1 Reply Last reply
      0
      • N Nibu babu thomas

        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 to ShellExecute.


        Nibu thomas A Developer Programming tips[^]  My site[^]

        N Offline
        N Offline
        Nikhil Trivedi
        wrote on last edited by
        #4

        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

        N 1 Reply Last reply
        0
        • G George L Jackson

          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

          N Offline
          N Offline
          Nikhil Trivedi
          wrote on last edited by
          #5

          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

          1 Reply Last reply
          0
          • N 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

            N Offline
            N Offline
            Nibu babu thomas
            wrote on last edited by
            #6

            Nikhil Trivedi wrote:

            java -jar C:\psae.jar world

            So in this case the command will be the same... Look up ShellExecute in MSDN. The lpFile parameter should be "java.exe" and lpParameters should be "-jar C:\psae.jar world".


            Nibu thomas A Developer Programming tips[^]  My site[^]

            N 1 Reply Last reply
            0
            • N Nibu babu thomas

              Nikhil Trivedi wrote:

              java -jar C:\psae.jar world

              So in this case the command will be the same... Look up ShellExecute in MSDN. The lpFile parameter should be "java.exe" and lpParameters should be "-jar C:\psae.jar world".


              Nibu thomas A Developer Programming tips[^]  My site[^]

              N Offline
              N Offline
              Nikhil Trivedi
              wrote on last edited by
              #7

              Thanks Dear friend. It really will help a lot. Nikhs Nikhil Trivedi

              N 1 Reply Last reply
              0
              • N Nikhil Trivedi

                Thanks Dear friend. It really will help a lot. Nikhs Nikhil Trivedi

                N Offline
                N Offline
                Nibu babu thomas
                wrote on last edited by
                #8

                Nikhil Trivedi wrote:

                It really will help a lot.

                Did it work. :)


                Nibu thomas A Developer Programming tips[^]  My site[^]

                N 2 Replies Last reply
                0
                • N Nibu babu thomas

                  Nikhil Trivedi wrote:

                  It really will help a lot.

                  Did it work. :)


                  Nibu thomas A Developer Programming tips[^]  My site[^]

                  N Offline
                  N Offline
                  Nikhil Trivedi
                  wrote on last edited by
                  #9

                  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.

                  D 1 Reply Last reply
                  0
                  • N Nikhil Trivedi

                    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.

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #10

                    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

                    N 1 Reply Last reply
                    0
                    • D David Crow

                      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

                      N Offline
                      N Offline
                      Nikhil Trivedi
                      wrote on last edited by
                      #11

                      I didn't get the point you raised. Can you explain me that with some example ? Thanks for your reply. Nikhs Nikhil Trivedi

                      D 1 Reply Last reply
                      0
                      • N 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

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        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

                        N 1 Reply Last reply
                        0
                        • D David Crow

                          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

                          N Offline
                          N Offline
                          Nikhil Trivedi
                          wrote on last edited by
                          #13

                          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

                          N 1 Reply Last reply
                          0
                          • N 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

                            N Offline
                            N Offline
                            Nikhil Trivedi
                            wrote on last edited by
                            #14

                            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

                            D 1 Reply Last reply
                            0
                            • N Nibu babu thomas

                              Nikhil Trivedi wrote:

                              It really will help a lot.

                              Did it work. :)


                              Nibu thomas A Developer Programming tips[^]  My site[^]

                              N Offline
                              N Offline
                              Nikhil Trivedi
                              wrote on last edited by
                              #15

                              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

                              1 Reply Last reply
                              0
                              • N 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

                                D Offline
                                D Offline
                                David Crow
                                wrote on last edited by
                                #16

                                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

                                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