2009
11.30

As recently I use Intellij most of the time due to fabulous Groovy support, I would like to use it also to play with JavaFX. There’s no planned support yet, so I played around with javafxc and javafx tools.

In Intellij there’s only support for syntax highlighting defined in Settings->File Types. There are two ways you can compile your files. First one is using External Tools. It’s good if you would like to compile only one file at a time. The second solution is creating an ant script.

I think that better solution is using ant build file to compile all *.fx files in your module. I used build file posted at stackoverflow.com:

<?xml version="1.1"?>

<project name="JavaFx" default="compile" basedir=".">
    <property environment="env"/>
    <property name="java.home" value="${env.JAVA_HOME}"/>
    <property name="jfx.home" value="${JAVAFX_HOME}"/>
    <path id="compile.classpath">
        <fileset dir="${java.home}/lib">
            <include name="**/*.jar"/>
        </fileset>
        <fileset dir="${jfx.home}/lib">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <taskdef classname="com.sun.tools.javafx.ant.JavaFxAntTask" name="javafxc">
        <classpath refid="compile.classpath"/>
    </taskdef>

    <target name="compile">
        <javafxc srcdir="${src}" destdir="${out}" includes="**/*.fx" executable="${jfx.home}/bin/javafxc.exe">
            <classpath refid="compile.classpath"/>
        </javafxc>
    </target>
</project>

Works perfectly.

Running is also simple. You need to create new External Tool for javafx.exe.
Go to Settings->External Tools and press Add button. After filling Name and Group there are three more fields needed:

  • Program:
    path to your javafx.exe
  • Parameters:
     -cp "$Classpath$" $FilePackage$.$FileNameWithoutExtension$
  • Working directory:
    $OutputPath$

The main disadvantage is that your fx file has to be placed in some package, but using packages is encouraged anyway, so it shouldn’t be a big issue.

You can run now your compiled fx class by right clicking on it and selecting external tool you just added.

1 comment so far

Add Your Comment
  1. [...] what else can you do to get some java fx love in IntelliJ?  At present not much, you can compile & run JavaFX using Intellij using the External Tools function or by using the ant script as specified in the [...]