• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic