+

Search Tips   |   Advanced Search

Calling Java code from a JavaScript adapter

Follow these instructions to instantiate Java objects and call their methods from JavaScript code in the adapter.

Attention: The name of any Java package to which you refer from within an adapter must start with the domains com, org, or net.

  1. Instantiate a Java object using the new keyword and apply the method on the newly instantiated object.

  2. Optional: Assign a JavaScript variable to be used as a reference to the newly instantiated object.

  3. Include the Java classes called from the JavaScript adapter in the project.under Worklight Project Folder/server/java. They are automatically built and deployed to the MobileFirst Server, and the result of the build is placed under Worklight Project Folder/bin


Example

var x = new MyJavaClass();
var y = x.myMethod(1, "a");


Parent topic: Develop the server side of a MobileFirst application