Calling Java method from JavaScript using ScriptEngine

Richard Taylor :

I'm using ScriptEngine, running JavaScript.

I want the JavaScript script to be able to call myFunction(), where myFunction() is a method inside a given class of mine.

I know it's possible to use importPackage for standard Java stuff, what about my own methods?

Please advise :)

Jacob Mattison :

According to this, when you do

importPackage(java.awt)

in a script, that's actually a shortcut for a built-in global variable called Packages -- "java.awt" is actually a shortcut for "Packages.java.awt". So you might try and see whether, if you create your own package called "com.mypackage.hello", the scripting engine can access Packages.com.mypackage.hello. I haven't been able to find any documentation on that, but it's worth trying.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a javascript function from java method in Cordova

From Java

Java: Returning an object from ScriptEngine javascript

From Dev

Calling a Java Method from the native code using jni

From Javascript

Calling method using JavaScript prototype

From Dev

calling a java servlet from javascript ajax post method

From Dev

Calling JAVA Method from XQuery

From Dev

Java calling a print method from a main function and using data from another separate method

From Java

Calling a Method from Constructor Method - Java

From Java

calling another method from the main method in java

From Dev

Calling external Javascript from Action Method

From Dev

Calling a C# method from JavaScript

From Dev

MVC Calling ActionResult Method from JavaScript

From Dev

Calling javascript Service/Method from array object

From Dev

Access calling object from Javascript method

From Java

calling a java servlet from javascript

From Java

Android/Java: Calling a method using reflection?

From Java

JAVA calling a method using a ternary operator

From Java

Calling Java Method from GWT JSNI

From Dev

Java - Calling method from child of abstract class

From Dev

calling Java method from jsp page

From Dev

Calling a Java method from a JavaFX webview

From Java

Calling a java method from c++ in Android

From Dev

Calling a static void Java method from JNI

From Java

java calling a method from another class

From Java

Calling a Java Method from Visual Basic 6

From Dev

Calling a Java static method with generics from Scala

From Java

Calling an overloaded java generic method from scala

From Dev

Calling a method on a Java class from Clojure

From Java

Calling Java Main method from static block

Related Related

HotTag

Archive