• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
linda russel
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a javascript file and i want to call that javascript in my java program. how do i execute that?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the classes and interfaces in the javax.script package.
 
linda russel
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
linda russel
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic