How are precompiled JavaScript modules loaded in RingoJS?

Ok, so I created a JavaScript file called test.js

that contains the following code:

print("It works!");


I compiled it with the Rhino JavaScript compiler without any errors. Then I created a new file named foo.js

that contains this code:

var test = require("./test.class");


Now when I run foo.js

in Ringo it throws the following exception and stack trace:

Uncaught exception:
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
Caused by: java.lang.NoClassDefFoundError: /home/aaditmshah/test (wrong name: test)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(
    at org.mozilla.javascript.DefiningClassLoader.defineClass(
    at org.ringojs.engine.ClassModuleLoader.load(
    at org.ringojs.engine.ReloadableScript.compileScript(
    at org.ringojs.engine.ReloadableScript.getScript(
    at org.ringojs.engine.ReloadableScript.exec(
    at org.ringojs.engine.ReloadableScript.load(
    at org.ringojs.engine.RingoWorker.loadModuleInternal(
    at org.mozilla.javascript.optimizer.OptRuntime.callName(
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3._c_script_0(/home/aaditmshah/foo.js:1)
    at org.mozilla.javascript.ContextFactory.doTopCall(
    at org.mozilla.javascript.ScriptRuntime.doTopCall(
    at org.mozilla.javascript.gen._home_aaditmshah_foo_js_3.exec(/home/aaditmshah/foo.js)
    at org.ringojs.engine.ReloadableScript.evaluate(
    at org.ringojs.engine.RingoWorker.evaluateScript(
    at org.ringojs.engine.RhinoEngine.runScript(
    ... 6 more
enter code here


I don't know where I am going wrong. I have the latest Ringo and Rhino 1.7R3. I added the current directory to my classpath by adding the following line to foo.js




However, it still generates the same error. I have no idea how to do this. Any help would be greatly appreciated.


source to share

1 answer

OK, I looked at the stack trace a little closer and realized that I found the class file correctly, it is just trying to load it from the wrong package ( home.aaditmshah.test

instead of just test

). If the class file is in your module path, you can only load it correctly with the module (class) name. By default, the current directory is not in the module path, so you need to add it first:

var test = require("test.class");




All Articles