- Java SDK 9 Early Access (or later)
- IntelliJ IDEA 2017.1 (or later with support for Java 9 modules)
- JavaFX with Java 9
- SQLite-native (as backend db, native libs included in sqlite-jdbc resources folder)
- Xerial SQLite JDBC Driver (v. 3.20.0)
This demo application is built to show you how you can structure your desktop JavaFX app similar to the Robotlegs approach. The structure in this app is highly inspired by Yennick Trevels blog post with using direct calls with interfaces over events because that makes it easier to follow the flow of your application. However this example does not use any dependency injection framework such as guice since I wanted to keep it as pure Java 9 as possible for instructional purposes. This app is also built with the new module approach in Java 9. The UI is built with pure Java code instead of using fxml since I prefer it that way giving me more control over my code. Also the UI is built to be resizable meaning the UI-components adapt their size when the main application windows is being resized.
SQLite with (Xerial SQLite JDBC Driver) is used as a backend with pure JDBC-calls for instructional purpose. The Xerial source is included as a module named sqlite-jdbc in the application.
- Add a logging framework module
- Add jOOQ as a module (and switch from pure JDBC-calls)
The application creates and populates a JavaFx-structure-demo.db file under the user home directory, System.getProperty("user.home").
- MacOS
/Users/username/JavaFx-structure-demo.db
- Windows
C:\Users\username\JavaFx-structure-demo.db
- Linux
/home/username/JavaFx-structure-demo.db
- MacOS
- compile with Java 9 SDK
- run with:
java -m com.example/com.example.Main
Build artifacts (jars) from the modules. From within Intellij choose Build->Build Artifacts...
Now the following two jars should have been created under the target folder:
- JavaFx-strucure-demo.jar (including a MANIFEST.MF-file containing "Main-Class: com.example.Main")
- sqlite-jdbc.jar
Run the following jlink command from the target catalog
- MacOS (61 MB)
jlink --output release/JavaFx-structure-demo --compress=2 --module-path="JavaFx-structure-demo.jar:sqlite-jdbc.jar:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods" --add-modules com.example,sqlite.jdbc
- Windows (59 MB)
jlink --output release/JavaFx-structure-demo --compress=2 --module-path="JavaFx-structure-demo.jar;sqlite-jdbc.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules com.example,sqlite.jdbc
- Linux (72 MB)
jlink --output release/JavaFx-structure-demo --compress=2 --module-path="JavaFx-structure-demo.jar:sqlite-jdbc.jar:/opt/jdk-9/jmods" --add-modules com.example,sqlite.jdbc
Usage:
From the release/JavaFx-structure-demo/bin folder run:
- MacOS/Linux
./java -m com.example/com.example.Main
- Windows
.\javaw -m com.example/com.example.Main