Forums Register Login

how to call a external javascripr file in my core java program?

+Pie Number of slices to send: Send
i have a javascript file and i want to call that javascript in my java program. how do i execute that?
+Pie Number of slices to send: Send
Since Java 6 there is the package javax.script (look it up in the API documentation) that you can use to run scripts in different scripting languages. An interpreter for JavaScript is included.

Can you explain in more detail what exactly you want to use this for? Is this JavaScript on a web page, which the browser normally runs for you?
+Pie Number of slices to send: Send
Check out the classes and interfaces in the javax.script package.
+Pie Number of slices to send: Send
Actually i just want to run a simple javascript which has a alert message by calling it in my java program.

Thanks for your previous replies.
+Pie Number of slices to send: Send
 

linda russel wrote:Actually i just want to run a simple javascript which has a alert message by calling it in my java program.



Frankly, that sounds like a pretty bad idea. Can you give some more context as to what exactly you're trying to do? Besides the obvious, that is. Are you writing a web application using JSPs? What is this Java program doing that it needs to make a call out to Javascript? Javascript is a client-side technology. Java programs run in a JVM. There's a huge chasm between those two that you're trying to bridge and people don't normally try to do that (think Evel Knievel jumping the Grand Canyon). Now as others have hinted, there are ways to legitimately work with Javascript from Java but I'm interested to see if your intent is compatibly legitimate.

(Edit: "Evel", not "Evil" - freudian slip?)
+Pie Number of slices to send: Send
Actually i am doing Selenium automation using webdriver API's , the problem is that i have few HTML5 components and HTML5 canvas for which i do not have any Webdriver API's so i am trying to call a external javascript
+Pie Number of slices to send: Send
 

linda russel wrote:Actually i am doing Selenium automation using webdriver API's , the problem is that i have few HTML5 components and HTML5 canvas for which i do not have any Webdriver API's so i am trying to call a external javascript



Ah, so you're actually doing some Evel Knievel stuff, huh? I don't do much work with WebDriver/Selenium at that level but there is a JavascriptExecutor interface documented here: http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html. That might be a place to start searching for a solution.


BTW, Java in General may not be the best forum to have this thread. Testing maybe? I'll defer that decision to the folks in charge of this bar though.
Can't .... do .... plaid .... So I did this tiny ad instead:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1195 times.
Similar Threads
Calling Data Transformation Services
Calling .js file from Java
JOptionPane No X11 DISPLAY error
calling java class file from javascript
code to run a java class fiel in java program itself
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:59:22.