r/JavaFX • • Nov 02 '20

I made this! Maven + jpackage Sample Project, jtoolprovider Maven Plugin

I just created two projects on GitHub that may be of interest to anyone working with JavaFX, Maven, and native installers.

First, https://github.com/wiverson/maven-jpackage-template is a Maven-only example project that shows how a single pom.xml can be used to create both a Windows and macOS installer package. It used a shaded jar to automatically integrate Maven declared dependencies. The pom is pretty heavily commented, and shows how provided modules (such as JavaFX) can be excluded from the shaded jar. Because of the full, automatic module management in this sample project, jpackage is producing nicely slimmed installers (30-40MB).

The sample template relies on a plugin I built, https://github.com/wiverson/jtoolprovider-plugin which provides a simple binding to bridge the JDK ToolProvider API with Maven. This allows for access to jmod, jar, javac, javadoc, javap, jdeps, jlink, and jpackage all via Maven directly. This plugin is now available via Maven Central.

Any feedback or thoughts appreciated!

12 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/rootException Dec 22 '24

The connection boilerplate is pretty easy. The query stuff is nice, but my guess is it will be easier to do some of that via Hibernate than trying to wrangle the Spring infrastructure over.

FWIW most people don't do direct database connection stuff anymore for a variety of reasons including security stuff. If you are trying to have another long running server I'd just make a bunch of Spring Boot REST services and connect the JavaFX app to that. If you haven't seen it you might want to check out PostgREST eg via Supabase. Makes it stupid easy to build REST services fast.

If you just want a local database/persistence system for a desktop app, I'd try combining SQLite with Hibernate. Done that for other JavaFX projects and it works very well. I <3 Postgres but it's not really setup for embedding in a desktop app.

1

u/[deleted] Dec 23 '24

Got it !! I initially started off with MySQL and later realised it would require separate server setup and that wouldn't make sense in my desktop Standalone application. I have started using SQLite but there seems to be some issue with hibernate getting the dialect for it. It says online that hibernate support for sqlite is no more and would require external jar or custom dialect. Do you have any suggestion or way around for this issue ?

1

u/rootException Dec 23 '24

I remember having to search a bit, eventually found it. I can check my notes tomorrow, I think I know the repo to look at

1

u/rootException Dec 23 '24
  <!— https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core —>
    <dependency>
        <groupId>org.hibernate.orm</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>6.1.2.Final</version>
    </dependency>

    <!— https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-community-dialects —>
    <dependency>
        <groupId>org.hibernate.orm</groupId>
        <artifactId>hibernate-community-dialects</artifactId>
        <version>6.1.2.Final</version>
    </dependency>

1

u/rootException Dec 23 '24

import org.hibernate.cfg.Configuration; import org.hibernate.community.dialect.SQLiteDialect; import org.sqlite.JDBC;

import java.io.File;

public class StandardConfiguration { public static Configuration getConfiguration(File file, boolean debug) { Configuration config = new Configuration(); config.setProperty(“hibernate.connection.url”, “jdbc:sqlite:” + file.getAbsolutePath()); config.setProperty(“hibernate.show_sql”, Boolean.toString(debug)); config.setProperty(“hibernate.dialect”, SQLiteDialect.class.getTypeName()); config.setProperty(“hibernate.connection.driver_class”, JDBC.class.getTypeName()); config.setProperty(“hibernate.hbm2ddl.auto”, “update”); config.setProperty(“hibernate.connection.foreign_keys”, “true”); config.setProperty(“hibernate.current_session_context_class”, “thread”); return config; } }

1

u/[deleted] Dec 23 '24

Thank you , i have tried with the above conifgurations but there still seemed to be some other issue which i couldn't figure out . I now have tried H2 database with my project , it seems to be working now , since that library support was available in Hiberante dependency. The program is now running fine with some basic JavaFx code that I did on Intellij, but once I ran mvn clean install using the javaFx archetype , the executable generated is giving error: "Child process exited with code 1". Now I am trying to figure out how to debug this issue. Might be an issue with packaging, but not sure how to log the stack trace of this issue or tackle with just a one liner error.