I installed the node-java module (https://github.com/joeferner/node-java).
I have two files under the same folder named 'Code', one is test.js which has the following code:
let java= require('java');
let mySumTest= java.import('MySumClass');
console.log(mySumTest.sum(2, 5));
The other file is MySumClass.java:
public class MySumClass{
public static int sum(int a, int b){
return a+b;
}
}
But when I try to run the test.js file (./Code> node test.js), the node.js command prompt says that:
Error: Could not create class MySumClass
java.lang.NoClassDefFoundError: MySumClass
Caused by: java.lang.ClassNotFoundException: MySumClass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It is possible that I misunderstood how to use the import function of the node-java module. Any help would be appreciated!