Download js-1.6R7.jar from net. Or you can use this pom.xml to download this jar file
<dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.6R7 </version>
</dependency>
How to setup rhino js in console:
I have put my this above jar into D:\.m2\repository\rhino\js\1.6R7\js-1.6R7.jar
creat one bat file like rhino.bat and put this command
java -classpath .;D:\.m2\repository\rhino\js\1.6R7\js-1.6R7.jar org.mozilla.javascript.tools.shell.Main
save it.
Now double click on that batch file you will get
js> prompt.
now you can check bit code here
js> print('Binod')
Binod
js> 37+57
94
js>
for quiting:
quit();
js> quit();
You can open windows application using js
js> runCommand("notepad"); // It will open notepad
0
js> runCommand("mspaint");
0
js> runCommand("calc");
0
js> runCommand("cmd", "/C", "date /T")
Fri 08/13/2010
create one java script like abc.js
function check(name) {
for(i=0;i<10;i++){
print(name);
}
}
js> load("abc.js");
js> check("Binod");
Binod
Binod
Binod
Binod
Binod
Binod
Binod
Binod
Binod
Binod
js>
How to use the Rhino javascript embedded into java code
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
/**
* @author Binod Suman
*/
public class Demo {
public static void main(String[] args) {
new Demo().check();
}
public void check(){
ScriptEngineManager engineMgr = new ScriptEngineManager();
ScriptEngine engine = engineMgr.getEngineByName("JavaScript");
try {
engine.eval("function sayHello(s,c) {" +" println('Hello, world! '+s+' '+c);" +"}");
Invocable invocableEngine = (Invocable) engine;
invocableEngine.invokeFunction("sayHello","Binod","Tecnotree");
} catch (ScriptException ex) { ex.printStackTrace();}
catch(Exception e){e.printStackTrace();}
}
}
Useful link:
http://www.mozilla.org/rhino/tutorial.html
Good Tutorial : http://www.mozilla.org/rhino/ScriptingJava.html
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/
Subscribe to:
Post Comments (Atom)
Thanks for the sample code. Have you found a method to load and execute an external JavaScript file from Rhino embedded in Java code?
ReplyDeleteHi Sutch,
DeleteRevoluza Anmeldung. Jetzt bei Revoluza anmelden und Dein Online Business am Adult Entertainment starten!
visit my site : online geld verdienen
how hast does this code run?
ReplyDelete[ Placing Code ]
ReplyDelete[ Functions ]
[ Events ]
[ Comments ]
[ Conditionals-looping ]
[ Hiding the JavaScript ]
[ Date object ]
[ Prompt Method ]
[ Alert Method ]
[ Confirm Method ]
[ write and writeln ]
[ Operators ]
[ Variable ]
[ When JS Statements Run ]
[ Objects ]
[ Examples ]
[ Glossary Terms ]
can someone explain me the scenarios where i can use javascript in java program ??
ReplyDeleteMalaysia & Singapore & brunei ultimate online blogshop for wholesale & supply korean accessories, accessories, earstuds, choker, rings, hair, bracelet & trinket accessories.
ReplyDeleteOffer 35 % wholesale discount. Ship Worldwide
my site - binary option brokers
Unquestionably imagine that which you said. Your favourite justification appeared to be
ReplyDeleteat the web the easiest thing to be mindful of. I say to you, I definitely get irked whilst people
think about issues that they just don't know about. You controlled to hit the nail upon the top and defined out the entire thing with no need side effect , other folks could take a signal. Will probably be back to get more. Thanks
My web site :: Geld Verdienen im Internet
My page: schnell geld verdienen
Thanks for sharing your info. I truly appreciate your efforts and I will be waiting for your further
ReplyDeletewrite ups thanks once again.
Feel free to surf to my web site binary options india
my website > one touch binary options
Yesterday, while I was at work, my cousin
ReplyDeletestole my iphone and tested to see if it can survive a thirty foot drop, just so she can
be a youtube sensation. My iPad is now destroyed and she has
83 views. I know this is completely off topic but I had to share it with someone!
My webpage - binary options trading system
I am sure this post has touched all the internet
ReplyDeletepeople, its really really good article on building up new blog.
My site; Geld verdienen Im Internet
Hello! Someone in my Myspace group shared this site with us so I came to take
ReplyDeletea look. I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers!
Excellent blog and wonderful design and style.
Feel free to surf to my blog; how to make money free online
My webpage :: earn Money Writing reviews
Helpful info. Fortunate me I found your site unintentionally, and I'm surprised why this coincidence didn't happened
ReplyDeletein advance! I bookmarked it.
My blog post - online Geld verdienen
Thanks for finally talking about > "Rhino JavaScript Tutorial, Rhino js using java code, JavaScript interface" < Liked it!
ReplyDeleteMy homepage ... make
money online for free
It іѕ apрrοpriаte time to maκе ѕome plans fοr thе future anԁ it іs tіme to be happy.
ReplyDeleteI've read this post and if I could I desire to suggest you some interesting things or tips. Perhaps you can write next articles referring to this article. I wish to read even more things about it!
My blog post: custom galaxy s3 case
It іs pегfect tіme tο make
ReplyDeletesοme ρlаns fог the futuге
and іt is timе to be happy. ӏ've read this post and if I could I wish to suggest you some interesting things or tips. Perhaps you could write next articles referring to this article. I want to read even more things about it!
Here is my web blog - iphone 5 case top 10
I all the time emailеd thiѕ wеbpаge pοst pagе to all mу associates,
ReplyDeletefοr thе reason that іf liκе to reаd it after that my lіnκѕ will too.
Αlѕo vіsit my homepage iphone accessories
I just like the helpful infο уou provide for your artіcles.
ReplyDeleteI will bookmark yοur wеblog and tаκe a look at onсe more right here regularly.
I'm moderately sure I'll learn many new ѕtuff propег here!
Goοd luck for the next!
Also visit my ѕite: www.Arab-Face.com
I wаѕ suggestеd this web site
ReplyDeleteby my сοuѕin. I'm no longer sure whether or not this publish is written through him as no one else recognize such designated approximately my problem. You are incredible! Thank you!
My web-site - iphone 4 cases
I really like what you guys tend to be up too. This type of
ReplyDeleteclever work and coverage! Keep up the great works guys I've added you guys to blogroll.
Here is my website ... Going at whitekidneybeanreview.com
Hi, i read your blog from time to time and i own a similar one and i was just wondering
ReplyDeleteif you get a lot of spam remarks? If so how do you reduce it, any plugin or
anything you can recommend? I get so much lately it's driving me crazy so any support is very much appreciated.
my weblog: how to get pregnant fast
I am sure this paragraph has touched all the internet users, its really really good article on
ReplyDeletebuilding up new webpage.
Visit my blog; Buy lift serum
This design is wicked! You certainly know how to keep a reader amused.
ReplyDeleteBetween your wit and your videos, I was almost moved to start
my own blog (well, almost...HaHa!) Fantastic job. I really enjoyed what you had
to say, and more than that, how you presented it.
Too cool!
Here is my web blog :: uy Le derme luxe
replica bags dubai zeal replica bags replica bags prada
ReplyDeletehop over to these guys replica bags from china click to find out more dior dolabuy have a peek at these guys replica louis vuitton bags
ReplyDelete