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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.