In JDK6, is there a way to load multiple scripts, each in a file, and have the one script reference a method of another script? Sort of like "include"?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Is there a limit to how many levels you can nest i
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to toggle on Order in ReactJS
if you happen to be trying to do this within ant, you might see this error:
but you can sidestep it:
I think you're after the load() method/property of Rhino's global object/scope
This will load a javascript source file, similar to how include/require will in PHP. Once you load a file, you'll be able to call and function or use any object defined in the loaded file.
This is how things work when you're using the Rhino shell, which is the only context I know (your question mentioned the Java SDK, which is outside my area of experience)
A real-life example this time, i.e. running the esprima parser with Rhino 1.7R4.
After running this code, you should see the output as follows:
So indeed, the trick is in reusing the
globalScope
object.As long as you use the same scope to execute each file, they will be able to reference functions and variables from previously executed files.