aspose file tools*
The moose likes Java in General and the fly likes how to call a external javascripr file in my core java program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to call a external javascripr file in my core java program?" Watch "how to call a external javascripr file in my core java program?" New topic
Author

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

linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
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

Joined: Aug 16, 2005
Posts: 14268
    
  21

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?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4640
    
    5

Check out the classes and interfaces in the javax.script package.


luck, db
There are no new questions, but there may be new answers.
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
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

Joined: Feb 26, 2001
Posts: 4708
    
    7

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?)


Junilu - [How to Ask Questions] [How to Answer Questions]
linda russel
Ranch Hand

Joined: Jan 05, 2012
Posts: 86
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

Joined: Feb 26, 2001
Posts: 4708
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call a external javascripr file in my core java program?