I'm using javax.script package for running external JavaScript files within Java application.
How can I import one JavaScript file into another JavaScript file, without using Java code?
I'm using javax.script package for running external JavaScript files within Java application.
How can I import one JavaScript file into another JavaScript file, without using Java code?
When you say without using java code, I am not completely sure what you mean, but this is a pure javascript that works (although it is calling java):
...proivided, of course, that I have the file named (say c:/temp/hellouser.js) with something like:
I tested the script using a groovy script:
and the output was:
I hope this is approximately what you were looking for....
=========================== UPDATE ===========================
Here's a cleaned up version that extends the Rhino script engine factory (because the engine itself is final):
Now,
loadScript(fileName)
is part of the engine and you can cleanly call it with JS like:or as I tested in Java:
Cheers.