Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » JSDT calling Java from Javascript - How to set Java Classpath for Rhino?
JSDT calling Java from Javascript - How to set Java Classpath for Rhino? [message #669594] Tue, 10 May 2011 21:13
Jim Garrison is currently offline Jim GarrisonFriend
Messages: 57
Registered: July 2009
Member
When running JS local Rhino debugging in Indigo M7 (20110505), I can't seem to find a way to give Rhino access to Java classes, either in the same project or in projects I have open in the same workspace. For example:

Java class:

package com.troux.test;
public class JSTestClass 
{
	public JSTestClass()
	{
		System.out.println("constructed");
	}
}


test.js:

print("starting");
var x = new com.troux.test.JSTestClass();
print("done");


Output from running test.js as local Rhino debug:

starting
js: uncaught JavaScript runtime exception: TypeError: [JavaPackage com.troux.test.JSTestClass] is not a function, it is object.


The fact that Rhino thinks com.troux.test.JSTestClass is a "JavaPackage" is a reflection of the default import behavior where it assumes that anything in the com.* namespace it doesn't recognize is a package until it finds otherwise. Playing around in the Rhino console, with the classpath set correctly, I can run the same script, in which case com.troux.test.JSTestClass is identified as being a "JavaClass", not "JavaPackage", and I am able to invoke the constructor.
Previous Topic:IWAB0523E Error moving resource: ...... Could not read from source when writing file
Next Topic:Can standalone js files be debugged in Rhino in eclipse?
Goto Forum:
  


Current Time: Fri Apr 26 15:46:17 GMT 2024

Powered by FUDForum. Page generated in 0.02826 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top