12 Replies Latest reply on May 3, 2012 11:59 PM by EJP

    Passing Parameters to jar from a link

    mycoffee
      Hi All

      I create a link in crystal report that will call a runable jar file. It works fine when I don't pass any parameter to it. But when I pass parms with the jar, it doesn't work

      (It doesn't need to be in CR, a shortcut has the same problem)

      I think I am doing something wrong here. Please help. Thank you

      This works
      \\servername\folder1\myjar.jar

      These don't work
      \\servername\folder1\myjar.jar parm1Val
      \\servername\folder1\myjar.jar%20parm1Val

      Edited by: mycoffee on May 2, 2012 9:58 AM
        • 1. Re: Passing Parameters to jar from a link
          baftos
          I think this is how window behaves when you don't give the name of an executable (javaw.exe) in the shortcut. You give the name of a document(.jar). Windows looks at the file association and invokes the proper exe, but does not know what to do with the rest of your command. This is a guess, I did not go in depth. Try to put this in the shortcut command:

          javaw -jar \\servername\folder1\myjar.jar parm1Val
          • 2. Re: Passing Parameters to jar from a link
            mycoffee
            baftos wrote:
            I think this is how window behaves when you don't give the name of an executable (javaw.exe) in the shortcut. You give the name of a document(.jar). Windows looks at the file association and invokes the proper exe, but does not know what to do with the rest of your command. This is a guess, I did not go in depth. Try to put this in the shortcut command:

            javaw -jar \\servername\folder1\myjar.jar parm1Val
            I can run it through the command line but to access it using a link ( from jsp and crystal report is kind of tricky)

            Still did not succeed
            • 3. Re: Passing Parameters to jar from a link
              baftos
              I did not mean to open a command prompt. I know nothing about CR, but right-click on your desktop, new schortcut, and enter it as the command to execute. Thist, at least, should work.
              • 4. Re: Passing Parameters to jar from a link
                mycoffee
                baftos wrote:
                I did not mean to open a command prompt. I know nothing about CR, but right-click on your desktop, new schortcut, and enter it as the command to execute. Thist, at least, should work.
                I can create a shortcut and it works with no parms
                The onlything I cannot do is passing the parameters dynamically when calling the jar from a link

                For example, if I create a jsp, or a crystal report how do I invoke the jar with the parms

                <_a h ref="C:\someFolder\ART.jar" >clcik here</_a> or:
                <_a h ref="C:\someFolder\ART.lnk" >clcik here</_a> with the link points to the jar

                where should I pass the parms to?

                Something like <_a h ref="java -jar C:\someFolder\ART.jar parm1Val" >

                Everyone, please help
                Thanks

                Edited by: mycoffee on May 3, 2012 6:48 AM
                • 5. Re: Passing Parameters to jar from a link
                  796283
                  What about Java Web Start? The JNLP file can pass parameters, however as I've never used it (yet), I'm not sure if you need to do anything special with the jar to be able to use it.
                  1 person found this helpful
                  • 6. Re: Passing Parameters to jar from a link
                    mycoffee
                    bogdana wrote:
                    What about Java Web Start? The JNLP file can pass parameters, however as I've never used it (yet), I'm not sure if you need to do anything special with the jar to be able to use it.
                    Thank you very much

                    I don't have many choices. The jar file is already existing and the crystal report currently embeded into a jsp to call it with out parameters . Now I want to pass some parms into the jar to do something more

                    What I can access and change the code are the jar file and the crystal report (that will translated into jsp after embeded)

                    If I can build a webapp to replace the jar, that would be a piece of cake :D Will call it like this: //server/mywebapp/myjsp.jsp?parm1=val1&parm2=val2 but for a jar, I cannot find something similar
                    • 7. Re: Passing Parameters to jar from a link
                      796283
                      Just took a look at one of Oracle's examples of a JNLP file and it looks like it'll be fine with an existing jar, though you may get a warning saying the jar is unsigned (if it's not signed) or telling you what security permissions are needed.

                      I'd try making a simple JNLP file for your jar with static parameters to see if it even works, then if it does, instead of linking to the jar / JNLP file in the jsp page, link to a different page that responds with a dynamic JNLP.

                      See:
                      Oracle's Example - http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html#example
                      Dynamic JNLP - http://www.coderanch.com/t/200653/JNLP-Web-Start/java/create-Dynamic-jnlp-files
                      • 8. Re: Passing Parameters to jar from a link
                        mycoffee
                        bogdana wrote:
                        Just took a look at one of Oracle's examples of a JNLP file and it looks like it'll be fine with an existing jar, though you may get a warning saying the jar is unsigned (if it's not signed) or telling you what security permissions are needed.

                        I'd try making a simple JNLP file for your jar with static parameters to see if it even works, then if it does, instead of linking to the jar / JNLP file in the jsp page, link to a different page that responds with a dynamic JNLP.

                        See:
                        Oracle's Example - http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html#example
                        Dynamic JNLP - http://www.coderanch.com/t/200653/JNLP-Web-Start/java/create-Dynamic-jnlp-files
                        Thank you

                        It is interesting

                        I think then I will stuck of calling the JNLP because the dynamic value I have is in the crystal report (or in the jsp). I cannot pass the parms from the jsp to the JNDP

                        If I cannot solve it, the final solutions would be a webapp that i would not like to do it because there are lot of work while the jar is already there
                        • 9. Re: Passing Parameters to jar from a link
                          796283
                          mycoffee wrote:
                          I think then I will stuck of calling the JNLP because the dynamic value I have is in the crystal report (or in the jsp). I cannot pass the parms from the jsp to the JNDP
                          If I understand correctly, if the dynamic value(s) is in the jsp page, then why can't you just pass (read: POST, or JSP Session) the value(s) to the JNLP handler page (this is another JSP page that instead of writing out usual HTML, it responds with a JNLP document). In the coderanch link, you would just split the JNLP string into two parts: everything before the dynamic parameters, and everything after. Put them together then write to the browser the completed JNLP.


                          If the values aren't in some easily accessible JSP format (just text on a page), you'd have to parse the page somehow (either at the JNLP handler page by sending it a copy of the referring page and reading line by line until you find what you're looking for, or before sending it to the JNLP handler page by some other means, i.e. jQuery).
                          • 10. Re: Passing Parameters to jar from a link
                            mycoffee
                            Thank you very much for all your trying to help
                            Problem is I cannot created any jsp page nor any dynamic jndp files. It is a packed software by some other company
                            All I can do is changing the crystal report that will be embeded into the jsp
                            I can have a link in the crystal report to link to the jar and I can alter the jar file to do something for me
                            it is really limited what I can do

                            If no solutions found, than I have to ask the customers to deploy a webapp in the same server to handle the work then I can call the jsp easily but it will be lot of work, and it is likely not going to be accepted by the customers
                            • 11. Re: Passing Parameters to jar from a link
                              mycoffee
                              I think I am getting close. I tried to make the link in CR like this and it works in Crystal report

                              java -jar \\server\folder\myjar.jar parm1Val

                              Will embed it into jsp to see how. Likely, it will work :D
                              • 12. Re: Passing Parameters to jar from a link
                                EJP
                                We seem to be talking about at least three different kinds of link at the same time. Windows desktop link (shortcut), Crystal Reports links, and Web page links (<a>). I don't know what a Crystal Reports link is but I'm pretty sure it must be distinct from the other two, which are also very different from each other.