Invoking JavaFX script from Java

Hi,
Just started working on javafx and got the error below while trying to invoke javafx from java.
/******************** my java code *************************/
package fxexamples;
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.SimpleScriptContext;
import javax.swing.SwingUtilities;
public class RunFX {
     public static void main(String[] args) {
          final DataObject myObj = new DataObject();
          Runnable fxScript = new Runnable() {
               public void run() {
                    ClassLoader loader = Thread.currentThread()
                              .getContextClassLoader();
                    ScriptEngineManager manager = new ScriptEngineManager(loader);
                    ScriptEngine engine = manager.getEngineByExtension("fx");
                    String script = "import fxexamples.FXtoJava;";
                    try {
                         engine.eval(script);
                    } catch (Exception ex) {
                         ex.printStackTrace();
          SwingUtilities.invokeLater(fxScript);
/*****************my fx file **************************/
import javafx.stage.Stage;
Stage {
title: "Die, Ajax! - Hello World"
width: 250
height: 50
/*******************stack trace********************/
javax.script.ScriptException: compilation failed
     at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:260)
     at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:149)
     at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:140)
     at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
     at fxexamples.RunFX$1.run(RunFX.java:30)
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Thanks in advance.

I too, am having problems with using JSR-223 to use JavaFX script from within Java, specifically using Java FX 1.1 and Java 6. Please see:
http://forums.sun.com/thread.jspa?threadID=5373145

Similar Messages

  • Calling javaFX script from Java program

    I am trying to call JavaFX script from a simple Java program. code as follows:
    import java.io.*;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    public class My{
    public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("fx");
    try {  
    InputStreamReader reader = new InputStreamReader(My.class.getResourceAsStream("first.fx"));
    engine.eval(reader);
    reader.close();
    } catch (Exception e) {
    e.printStackTrace();
    my first.fx file code is here:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.scene.text.TextAlignment;
    Stage {
    title: "My First JavaFX Sphere"
    scene: Scene {
    width: 250
    height: 250
    content: [
    Text {
    font: Font { size: 24 }
    x: 20, y: 90
    textAlignment: TextAlignment.CENTER
    content:"Welcome to \nJavaFX World"
    } //Text
    ] // content
    } // Scene
    } // Stage
    I am not able to run My.java. runtime error as follows:
    java.lang.NullpointerException
    Kindly correct me, where I am wrong

    I am able to call .fx file from Java. Thank you all for helping me to resolve this problem
    Regards,
    Ritu

  • Invoking Shell Script from JAVA Stored procedure

    I am trying to invoke shell script using Java Stored procedure.
    When I run my java class outside of oracle using oracle user
    account it works but as soon as i load it into database and try
    to inovoke that class using PL/SQL wrapper it runs java class
    but is not able to invoke the shell script. Any ideas would be
    greatly appreciated.

    Pleass search the forums for "runtime" as there are many threads and examples already posted.

  • Invoking shell script from java

    I hava a shell script on a unixbox which needs to be invoked through a web application. How do I do it? What is the method to login,and then invoke the shell script? Also, should the password be directly mentioned in the java file?

    Pleass search the forums for "runtime" as there are many threads and examples already posted.

  • Invoke perl script from JAVA 1.4.2

    Hello All,

    Has this been resolved?
    I'm having an issue with it also, using the command line as such:
    j2sdk-1_4_2_02-windows-i586-p.exe /s /v "/qn ADDLOCAL=jrecore IEXPLORER=0 INSTALLDIR=D:\Progra~1\j2sdk-1_4_2_02 REBOOT=Suppress JAVAUPDATE=0 /L D:\temp\jvm142install.log"
    I've also tried different variations of the commands in "", but still no luck.
    From the command prompt it appears to hang, but comes back to the command prompt about 10 seconds later and nothing gets installed.
    Previous to installing it from the command line, I had installed it manually, and ran add/remove programs to remove it from the system.
    Is there something I should check in the registry that might be prevening the above command to run?
    InstallSheild's web site was helpful, but gave command line options for the msiexec to run.
    Any help would be appreciated!

  • Invoking unix shell scripts from java?

    Hi,
    could someone explain to me how one wuld invoke unix shell scripts from java.
    Also, could you invoke Visual Basic scripts from java.
    Finally, could you do this from an EJB?
    thanks for any help....
    sudu

    I just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
    --Ian                                                                                                                                                                                                                                                                                       

  • Invoking a bash shell script from Java code

    Hi All
    I am trying to invoke a Bash shell script using java code. The arguments required are "source wmGenPatch <source dir> <destination dir> no_reverse.
    in the code I have specified the arguments considering the cannonical paths of the files as the code may run on Unix or windows platform.
    I am getting a error while invoking Runtime.getRuntime().exec(args). The error is as follows :
    "The Error Occurred is: CreateProcess: source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=2"
    It seems that error=2 indicates that the 'file not found' exception. But i can see the directories referred to in the error at place in the workspace.
    Kindly advice.
    Thanks in advance.

    Hi All
    I am pretty new to invoking bash shell scripts from java and not sure if i am progressing in right direction.
    The piece of code tried by me is as follows
    try {
                   currentDir = f.getCanonicalPath();
              } catch (IOException e) {
              if (currentDir.contains("/")) {
                   separator = "/";
              } else {
                   separator = "\\";
              String args[] = new String[7];
              args[0] = "/bin/sh";
              args[1] = "-c";
              args[2] = "source";
              args[3] = currentDir + separator + "DiffEngineScripts" + separator
                        + "v4a02" + separator + "wmGenPatch";
              args[4] = sourceFileAdd;
              args[5] = destFileAdd;
              if (isReverseDeltaRequired) {
                   args[6] = "reverse";
              } else {
                   args[6] = "no_reverse";
              try {
                   Process xyz = Runtime.getRuntime().exec(args);                              
                   InputStream result = xyz.getInputStream();
                   InputStreamReader isr = new InputStreamReader(result);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ( (line = br.readLine()) != null)
                        System.out.println(line);
                   int exitVal = xyz.waitFor();
                   System.out.println("Leaving Testrun.java");
              } catch (Throwable t) {
                   t.printStackTrace();               
    and on running the same i am getting Java.io.IOException with the stack trace
    java.io.IOException: CreateProcess: \bin\sh -c source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=3
    kindly advice
    Thanks in advance

  • Start JavaFX application from Java

    Hello,
    I have the following scenario:
    I have a small JavaFX application and a big Java application. Now the Java App should call the JavaFX App to start up.
    Further the JavaFX App has to call some methods from the Java App. Is this possible?
    What is the best approach for my scenario?
    Maybe somebody has made some experiences ..
    thanks!
    Edited by: 799878 on 03.11.2010 07:54

    "Now the Java App should call the JavaFX App to start up."
    I'm assuming that the JavaFX code and the Java code are in the same application, correct? If so, then there are hacks available, but no standard way to start up JavaFX from Java will exist until the APIs have been ported from JavaFX script to Java.
    "Further the JavaFX App has to call some methods from the Java App. Is this possible?"
    Yes. Java can be called from JavaFX just fine. Just be careful if you use multi-threading or time consuming operations, since JavaFX script is apparently single threaded. Also be aware that netbeans normally compiles JavaFX applications with JSE version 1.5, so library features that did not exist until later versions will not be available by default.

  • Invoke beanshell methods from java

    Hello
    I'm learning beanshell and using it to write scripts that are ran in JDK 6.
    My question is how to invok beanshell methods from java source codes.
    My codes is:
    import javax.script.*;
    public class InvokeFunctions {
    public static void main (String[] args)throws ScriptException, NoSuchMethodException
    ScriptEngineManager sem = new ScriptEngineManager();
    ScriptEngine bshEngine = sem.getEngineByName("beanshell");
    String script = "public void sayHello()"+"{print (\"sayHello() is a method in bsh script\");}";
    bshEngine.eval(script);
    Invocable inbshEngine = (Invocable)bshEngine;
    inbshEngine.invokeFunction("sayHello");
    I defined a method "sayHello()" using beanshell, but i just can't invoke it in Java.
    I got an error msg said:
    Exception in thread "main" java.lang.IllegalAccessError: tried to access method bsh.NameSpace.getThis(Lbsh/Interpreter;)Lbsh/This; from class bsh.engine.BshScriptEngine
    Any one has any idea about it?
    Thanks

    Look at the Javadoc documentation of IllegalAccessError. It says:
    Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
    Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
    Maybe recompiling all your sources (make sure you delete all existing *.class files) will help?

  • Calling JavaFX Script from JavaScript on mobile

    Hi,
    We are developing a application which would run on a mobile. We have to call javafxscript from javascript in this application. Is there a way to do this on a mobile application. I am able to do this for application running on browsers.
    Will javafx mobile application support this Calling JavaFX Script from JavaScript?
    Please share any information related to this.
    Regards,
    Sherlyn

    I doubt it (but I can be wrong!).
    javafx.stage.AppletStageExtension is only on the desktop profile.
    [Calling From JavaScript to JavaFX Script|http://javafx.com/docs/tutorials/javafx-javascript/] article states "+this functionality requires Java SE 6 Update 10 at minimum+" which seems incompatible with mobile usage.
    Beside, a quick Google search hints that JavaScript support on mobile browsers is weak or inexistent (depending on browsers).

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Run a UNIX Script from java

    Hi,
    how can i run a unix script from java application. This java application is on windows.
    How can i do this.
    thanks,

    Hi,
    how can i run a unix script from java application.
    This java application is on windows.
    So I think it's safe to assume that the target script is on a remote unix server.
    Take a look at http://sourceforge.net/projects/sshtools/

  • Excute unix script from java.

    Hi need to excute unix script from java application.
    My code is:
    public class Test
    public static void main(String args[])
         try{
         p = Runtime.getRuntime().exec("./qfe0"); //qfe0 is the name of the script.
    p.waitFor();
    catch(Exception e)
    e.printStackTrace();
    My problem is that using the waitFor() statement stuck the the script. if i don't use the waitFor() it works good but then i don't know when the script is finished.
    Any idea?

    The problem is likely to be that you script is either waiting for input or has filled the stdout buffer and you are not emptying it. Search this forum for this as its been answered many times before.

  • How execute Unix script from java?

    Can I execute Unix script from java?

    Yes. Using ProcessBuilder. And read [When Runtime.exec() wont|http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html]. It's old, but pretty much all of it is still true.

  • How to invoke dos shell from java program

    Hi,
    I'm not able to invoke dos shell from java.
    Can any one help me in this issue.
    I'm providing the source code below:
    try{
    Runtime.getRuntime().exec("cmd.exe")
    catch(IOException e) {
    System.out.println(e.getStackTrace());
    Thanks

    Does it throw a different exception?
    Or does it just do nothing at all?
    It does nothing at all[/b
    Is this a standalone Java app?
    Or a Java Applet running via a webbrowser? [b]It's a standalone application

Maybe you are looking for

  • Java connectivity with EXCEL/WORD

    I am developing a Java application where the data is in SQL Server/Visual FoxPro. Some calculations are performed on this data using Java (JSP). I have to take the report in a pre-formatted EXCEL/WORD template as this EXCEL document has to be sent to

  • Reg b2b and b2c in account identification in webclient

    Hi gurus, is there any provision to use both b2b and b2c in account identification profile in a webclient profile. Thanks in advance.

  • Recommended Photo Album Software? (PSA 3.0 SE?)

    I have used Photoshop (v6.0 thru CS) for some time now. I use this for both complex and simple imaging editing. I have no real intention/desire to use any "simplified" solution for basic editing. I need a Windows based Photo Album solution to view, c

  • Apple works fails to launch

    I just updated my mac to leopard and when I try to open appleworks 6 a window comes up giving me the option to ignore, report or relaunch. It will not relaunch so I reported it. What do I do to fix this.

  • Notebook Toshiba L40 don't start when unplug power cable

    When i unplug power cable system don't start and crash on login KDE or faster. When power cable is plug everything is ok. Tested on Kubuntu 9.04, Windows Vista and works ok. On Kubuntu 9.10 alpha 5 i have the same problem. Sorry for my english