This discussion is archived
7 Replies Latest reply: Mar 20, 2013 11:26 AM by rukbat RSS

Call Java method from JavaScript

920441 Newbie
Currently Being Moderated
Hi,

I want to call a java method from a javascript.

I have java API (jar), which contains more number of classes and methods. How can i import / refer java classes into javascript from a jar file. I referred many forums and sites but could not get the possible solutions. Any one suggest me to do this.

Regards,
Sasi

Edited by: sasi on Mar 19, 2013 9:08 PM
  • 1. Re: Call Java method from JavaScript
    997752 Newbie
    Currently Being Moderated
    Can you elaborate your problem as why you want to call java method in javascript? so we will answer you in more specific and correct way.
  • 2. Re: Call Java method from JavaScript
    Kayaman Guru
    Currently Being Moderated
    sasi wrote:
    I want to call a java method from a javascript.
    You can't. At least not directly.
    I have java API (jar), which contains more number of classes and methods. How can i import / refer java classes into javascript from a jar file.
    If you're running the javascript in a browser, your only choice is to communicate with a backend server through HTTP or other available protocol. Of course this won't give you direct access to Java methods or classes.

    What are you really trying to do?
  • 3. Re: Call Java method from JavaScript
    baftos Expert
    Currently Being Moderated
    Previous answers are correct in light of the little information we have. But:
    If you talking about a web page containing javascript, this javascript code can communicate with a Java applet in the same page.
  • 4. Re: Call Java method from JavaScript
    gimbal2 Guru
    Currently Being Moderated
    baftos wrote:
    Previous answers are correct in light of the little information we have. But:
    If you talking about a web page containing javascript, this javascript code can communicate with a Java applet in the same page.
    Aha, but the question was: HOW ;)

    Doing a google for "javascript invoke applet method" gives the answer quite quickly and completely. Either the OP is lying about his research actions, or he's not interested in applets.

    http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html
  • 5. Re: Call Java method from JavaScript
    baftos Expert
    Currently Being Moderated
    Before going into this delicate matter, I wanted to know if it is browser JavaScript, which is the most common, but not only place where we can find JavaScript.
    If, so, is the jar an applet or just a container of useful classes? If just a container, maybe it can be wrapped in an applet etc. etc. Just wanted to avoid useless talk before we know more about the context.
  • 6. Re: Call Java method from JavaScript
    920441 Newbie
    Currently Being Moderated
    yes baftos, it is a browser javascript. jar contains useful classes. That classes internally inherits swing classes like JFrame,JPanel.

    In my peoplesfot development, if i place Guiffy.jar file into %PS_HOME%\class directory and if i call that class which is embedded in jar, it will executed on application server in the same machine. But i want to execute that jar in webserver on client machine and finally display the result on client browser or GUI form of Guiffy. It should not be depend on application server. so i chose the option to call Guiffy class from javascript to execute on client side.
  • 7. Re: Call Java method from JavaScript
    rukbat Guru Moderator
    Currently Being Moderated
    I suggest you go back to your active thread in the PeopleSoft forum:
    Execute Java file (jar) on client side
    and continue working on your issue where you started it, three weeks ago.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points