This discussion is archived
2 Replies Latest reply: Nov 28, 2011 2:20 PM by jsmith RSS

How to compile JavaFX 2.0 app with javac.exe from command prompt?

800600 Newbie
Currently Being Moderated
I downloaded JavaFX 2.0 SDK and build a few apps in NetBeans. All went well and I liked it.

But one thing that I don't understand is that it seems no way to compile JavaFX 2.0 programs with javac.exe from command prompt. I added jfxrt.jar to the classpath but still won't do.

Does anyone know how to compile JavaFX 2.0 with javac.exe from command line? What do I miss if I want to do this?

Thanks.
  • 1. Re: How to compile JavaFX 2.0 app with javac.exe from command prompt?
    875756 Pro
    Currently Being Moderated
    Adding jfxrt.jar to the classpath should work fine. There is no real magic to the compiling (running is another issue).

    If you're still having problems post your compile command line code and the resulting error.
  • 2. Re: How to compile JavaFX 2.0 app with javac.exe from command prompt?
    jsmith Guru
    Currently Being Moderated
    As an example, attached is a very basic sample script for JavaFX command line development under Windows.

    If you just want to do only the compilation step, then just use the line which says javac, you don't need the other stuff.
    rem cleanup the output directories
    rd /S /Q out
    rd /S /Q dist
    rd /S /Q dist-web
    
    rem create the compile output directory
    mkdir out
    
    rem compile the source
    "%JDK_HOME%\bin\javac" -sourcepath src src\willow\*.java -classpath "%JAVAFX_SDK_HOME%\rt\lib\jfxrt.jar;lib\*" -d out
    
    rem copy the resources to the output
    copy resources\willow\* out\willow\*
    
    rem package the app as a click to run jar
    "%JAVAFX_SDK_HOME%\bin\javafxpackager" -createjar -appclass willow.Willow -srcdir out -classpath lib\image4j.jar;lib\PDFRenderer-0.9.1.jar -outdir dist -runtimeversion 2.0 -outfile willow.jar -v
    
    rem copy the lib files to the distribution
    mkdir dist\lib
    copy lib\*.jar dist\lib
    
    rem package the app as a webstart app and applet
    "%JAVAFX_SDK_HOME%\bin\javafxpackager" -deploy -outdir dist-web -outfile Willow -width 1121 -height 600 -name Willow -appclass willow.Willow.class -v -srcdir dist -srcfiles Willow.jar;lib\image4j.jar;lib\PDFRenderer-0.9.1.jar
    Input setup:
    - Assumes you have downloaded and installed JavaFX.
    - Looks for java source files under a src directory.
    - Looks for any supporting (non jfxrt.jar) jar files under a lib directory.
    - Looks for resources (images, css, etc) under a resources directory.
    - Assumes a JDK_HOME and JAVAFX_SDK_HOME environment variable is set.
    - Only compiles all java files in a single package (not recursively).

    Output directory setup:
    - out: compilation output directory (class files and associated resource files).
    - dist: clickable executable jar file for the application.
    - dist-web: html applet and webstart jnlp for the application.

    If you want to adapt the sample script for your use, things you will need to do:
    1. Install a Java SDK and the JavaFX SDK.
    2. Set JDK_HOME and JAVAFX_SDK_HOME system environment variables to point to the relevant home directories.
    3. Change lib\image4j.jar;lib\PDFRenderer-0.9.1.jar to the names of any lib files you have in your lib directory (for simple apps you don't need any lib files).
    4. Change references to willow.Willow to the qualified name of your application class.
    5. Change the references to the willow package to whatever your package name is e.g. org.acme.dynamite.

    To run the resultant application use java -jar dist\<appjar>.jar or double click on the jar in Explorer.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points