sbt-fxml is the missing link for your JavaFX FXML files and your codebase. If you have used the Android IDE or playframework before, you will feel right at home.

This is beta software with a not yet stabilized API. It is built against SBT 0.12.x.


Add this to your project/plugins.sbt:

resolvers += Classpaths.sbtPluginSnapshots

addSbtPlugin("org.bitbucket.phdoerfler" % "sbt-fxml" % "1.0-SNAPSHOT")

And this to your build.sbt:

import sbtfxml._


sourceGenerators in Compile <+= generateFXMLBindings

and sbt-fxml will start looking in your resourceDirectories for fxmlFiles and generate controller classes for them in sourceManaged / "scala".


Change the filter for .fxml files:

fileFilter := """.*\.fxml""".r.pattern

Or alter the set of FXML files directly:

fxmlFiles <<= (resourceDirectories in Compile, fileFilter) map { (rDirs, filter) =>
  (rDirs ** new PatternFilter(filter)).get

That's it, for now.

Example Output

// Auto generated by sbt-fxml, changes will be overwritten

package com.example

import javafx.fxml.FXML
import javafx.scene.control.Button

object Controller {
  var meep: Button = ???

Based on this FXML (from SceneBuilder):

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="com.example.Controller">
    <Button fx:id="meep" layoutX="89.0" layoutY="33.0" text="Button" />


  • Provides You with compile time checks for FXML files
  • Generates beautiful, almost hand written code
  • Guesses the package and controller class name based on the fx:controller attribute
  • Avoids unnecessary imports
  • Handles default packages
  • Creates a directory structure matching the package
  • Uses the JavaFX library jar to lookup all required classes for your scene graph, so it will automatically work with any past and future JavaFX release
  • Only recreates classes if the FXML has changed
  • Supports continuous compile ~compile for automatically picking up your changes on the fly


This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html