Skip to content

A JavaFX demo application which uses a similar to RobotLegs structure. Built with Java 9-ea (jdk-9+180) and the new module approach (project jigsaw).

Notifications You must be signed in to change notification settings

jbilander/JavaFx-structure-demo

Repository files navigation

Prerequisites

  • Java SDK 9 Early Access (or later)
  • IntelliJ IDEA 2017.1 (or later with support for Java 9 modules)
  • Maven 3 (maven-compiler-plugin v3.6.2 support for compiling java 9 modules)

Technologies used

  • JavaFX with Java 9 (using modules)
  • SQLiteConnectionPoolDataSource
  • SQLite-native (as backend db, native x86_64 binary libs included in below driver)
  • Forked Xerial SQLite JDBC Driver (v3.20.0) with support for encryption (SQLCipher)

About

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 window is being resized.

Backend

SQLite with Forked Xerial SQLite JDBC Driver (v3.20.0) with support for encryption (SQLCipher) is used as a backend with pure JDBC-calls for instructional purpose. The driver has native binary libs (dll, jnilib, so) included for 64-bit Windows x86_64, MacOSX x86_64 and Linux x86_64 platforms.

Output

The application creates and populates an encrypted 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

Screenshot of application

MacOS

Windows

Linux Mint

Usage

compile and package with Maven/Java 9 SDK

  • mvn package

Please note that you have to do mvn install first on sqlite-jdbc-sqlcipher projects so that the depending jar is installed in your .m2 maven repo.

Create a reduced native runtime image with jlink

Run the following jlink command from the target catalog

  • MacOS (51 MB) Obviously this can be stripped down further removing the binaries not used for MacOSX in sqlite-jdbc-sqlcipher project.

jlink --output release/JavaFx-structure-demo --compress=2 --strip-debug --module-path="JavaFx-structure-demo-1.0.jar:$HOME/.m2/repository/org/xerial/sqlite-jdbc-sqlcipher/3.20.0/sqlite-jdbc-sqlcipher-3.20.0.jar:/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home/jmods" --add-modules sqlite.jdbc

  • Windows (51,4 MB) Obviously this can be stripped down further removing the binaries not used for Windows in sqlite-jdbc-sqlcipher project.

jlink --output release/JavaFx-structure-demo --compress=2 --strip-debug --module-path="JavaFx-structure-demo-1.0.jar;%homepath%.m2\repository\org\xerial\sqlite-jdbc-sqlcipher\3.20.0\sqlite-jdbc-sqlcipher-3.20.0.jar;C:\Program Files\Java\jdk-9\jmods" --add-modules sqlite.jdbc

copy the libeay32.dll (shell\Windows\x86_64\libeay32.dll) from the sqlite-jdbc-sqlcipher project into your release\JavaFx-structure-demo\bin folder.

  • Linux (62 MB) Obviously this can be stripped down further removing the binaries not used for Linux in sqlite-jdbc-sqlcipher project.

jlink --output release/JavaFx-structure-demo --compress=2 --strip-debug --module-path="JavaFx-structure-demo-1.0.jar:$HOME/.m2/repository/org/xerial/sqlite-jdbc-sqlcipher/3.20.0/sqlite-jdbc-sqlcipher-3.20.0.jar:/opt/jdk-9/jmods" --add-modules 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

Use the javapackager if you want to make a native package for distribution, more about that here

About

A JavaFX demo application which uses a similar to RobotLegs structure. Built with Java 9-ea (jdk-9+180) and the new module approach (project jigsaw).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published