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 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