Reputation: 131
Is there a way to execute a java script from within a java program in a step-by-step manner?
I know how to call javascript from java. I know about Rhino or Beanshell. No web server involved.
What I'm trying to achieve: Have multiple scripts execute semi concurrently scheduled by a scheduler where each script gets a 'tick' every now and then in which it executes one atomic command just like in a debugger. This should also 'step into' functions and for/while loops.
I need to call the script 'tick' at a specific time (and return immediately) so real threads are no use.
So I guess i want a way to debug a script from within a java program without a debugger (and its overhead) involved. Just stepwise execution is needed.
Any ideas?
Upvotes: 4
Views: 342
Reputation: 3162
Check out these links:
https://www.mozilla.org/rhino/tutorial.html https://blogs.oracle.com/blue/entry/scripting_with_servlets_rhino_part
They will help u get started.
Upvotes: 0
Reputation: 1192
Yes, it is possible by using an interpreter. More specifically, you need an JavaScript interpreter that can be executed on the JVM. Rhino seems to be the most popular one.
If you are running scripts concurrently then you will need an interpreter for each concurrent script.
Upvotes: 3