Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 622641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:00:25+00:00 2026-05-13T19:00:25+00:00

I am writing a JavaScript program in Rhino which needs to load other JavaScript

  • 0

I am writing a JavaScript program in Rhino which needs to load other JavaScript files. However the built-in load() function loads files relatively to the current directory and I need to load them relatively to the location of the script (so that the program can be called form any directory).

In other languages I would use something like dirname(__FILE__) + "/path/file", but it seems that Rhino does not have __FILE__ or anything similar. I have tried to extract the current file from a thrown exception, but it is empty, i.e. the following code prints “true”:

try {
  throw new Error();
} catch (e) {
  print(e.fileName === "");
}

I tried to look at the interpreter sources and use the Java-JavaScript bridge, but I didn’t find anything helpful yet (I’ll probably look more).

Does anybody have a tip how to make loading files on relative paths work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:00:25+00:00Added an answer on May 13, 2026 at 7:00 pm

    It’s probably easiest to get users to run a launcher script. If you’re on a *nix or OS X, you could put a shell script into the same directory as all your Javascript, which changes the directory to your script’s dir before launching:

    #!/bin/sh
    cd `dirname "$0"`
    java -jar js.jar your_script.js
    

    If your script needs to run in the user’s current directory, you could instead have the wrapper pass its location in on the command line:

    #!/bin/sh
    DIR=`basename "$0"`
    java -jar "$DIR/js.jar" "$DIR/loader.js" "$DIR"
    

    Then in loader.js, use Rhino’s builtin arguments variable to access “$DIR”:

    load(arguments[0] + "/another_js_file.js");
    

    The Rhino functions are documented here.

    Something similar may be possible on Windows; I don’t know much about CMD.EXE batch files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a little program in JavaScript in which I want to parse the
I have a very basic JavaScript question. I am writing a program which will
In JavaScript (server side NodeJS) I'm writing a program which generates XML as output.
I'm writing a small JavaScript program that makes web calls to pull up weather
I am writing a JavaScript function to highlight the row and column of a
I'm writing a Javascript function that would manipulate an array written on-the-fly and sent
I'm writing some Javascript code and I'm trying to change the current page as
I am writing a JavaScript that currently needs to support older browsers (like IE
I'm writing a piece of client-side javascript code that takes a function and finds
I am writing a program in Javascript, CoffeeScript and jQuery to be exact. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.