node-java icon indicating copy to clipboard operation
node-java copied to clipboard

java.lang.NoClassDefFoundError

Open arjunrai1t opened this issue 8 years ago • 5 comments

Dear Sir i want to load my jar thorugh your api but it always show java.lang.NoClassDefFoundError. This is my sample code which i written: My Code: var java = require("java"); var path = require('path'); var fs = require('fs'); var version = java.callStaticMethodSync("java.lang.System", "getProperty", "java.version"); java.classpath.push('.'); java.classpath.push("commons-lang3-3.1.jar"); java.classpath.push("commons-io.jar"); java.classpath.push( path.resolve('C:\webkit\test.jar') ); console.log("Java Version: "+version); console.log("Java Classpath: "+java.classpath); java.classpath.push(path.join(__dirname, "test.jar")); console.log('jar exists: ' + fs.existsSync(path.join(__dirname, "test.jar")));

java.newInstance("test.Sample", function(err, list2) { if(err) {
console.log(err); return; }else{ console.log("Sample class load successfully"); }

});

But when i run by prog by node it always show unable to find class. I already test this jar with another java class file its works fine. Please give me solution

arjunrai1t avatar Dec 18 '17 10:12 arjunrai1t

You have to set up the classpath BEFORE calling any Java method.

jzakrzewski avatar Dec 18 '17 10:12 jzakrzewski

I have already done this but same issue happened

On 18-Dec-2017 4:22 pm, "Jakub Zakrzewski" [email protected] wrote:

You have to set up the classpath BEFORE calling any Java method.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joeferner/node-java/issues/419#issuecomment-352392211, or mute the thread https://github.com/notifications/unsubscribe-auth/AEU96CK0Ww6J0YX98AvDL4beUjLUZNkjks5tBkPrgaJpZM4RFP06 .

arjunrai1t avatar Dec 18 '17 14:12 arjunrai1t

I had issues with classpath and special characters. Can you post the full value of java.classpath ?

antoinepairet avatar Feb 01 '18 21:02 antoinepairet

@malay0345 Did you manage to fix this issue ? Im running into the same problem with my own .jar

RenanChagas avatar Apr 25 '18 08:04 RenanChagas

+1

MichaelIT avatar Feb 18 '19 14:02 MichaelIT