r/JavaFX • u/artistictrickster8 • Jul 16 '24
Help Howto create a JavaFx project, with which pom (or no pom?) how to start it?
Hello, Pls I use Java11 (bellsoft). I want to try a JavaFx project (a very simple editor), but I am a little bit confused. Usually, I take whatever pom.xml and adjust it, and also run it. mvn run or such. How do I do this with JavaFx? (I do not want to use gradle, at all, only maven). .. I found the archetype with a pom from openjfk and I do not understand how to start it.
I understand to create a project with a direct link to the classpath, like: javac -cp a.jar myClass.java and run it like that, too: java -cp a.jar myClass .. with several .jars in the classpath.
Is that the way to do with JavaFx?
Edit: thank you all for your help!! :)
3
u/xdsswar Jul 16 '24
Use Intellij IDE it has project setup to build all for you.
3
u/wildjokers Jul 16 '24
https://openjfx.io/openjfx-docs/#maven
2
u/BlueGoliath Jul 16 '24
Use Netbeans to create the JavaFX project. Use javafx:run to run it from terminal or you can use the green run button.
1
u/[deleted] Jul 17 '24
Any reason for version 11? Why not 17 or 21?
Here you find a simple hello world project with Maven support. You can try it and use it as a starting point if you want: https://github.com/armin-reichert/hellofx
If you are using IntelliJ, you can execute the application by right-clicking the class named "Main" and selecting "Run Main.main()" from the context menu.
No need to fiddle around with runtime configuration settings as other commentators suggested.
1
u/wildjokers Jul 17 '24
I am curious why? Gradle has a great plugin called The Badass JLink Plugin that makes it very easy to package a java app with a slimmed down and bundled runtime which is great for JavaFX (and Swing) apps. Here is a template project that comes out-of-the-box ready to go:
https://github.com/mjparme/javafx-template
It is largely based on the example found at https://openjfx.io/openjfx-docs/#gradle with the jlink plugin added.
1
u/Sweet-Teacher-996 Aug 30 '24
We from JPro have a minimal JavaFX Helloworld Template project on GitHub:
Maven -> https://github.com/JPro-one/HelloJPro-Maven
Gradle -> https://github.com/JPro-one/HelloJPro
You can fork them and open them in IntelliJ.
(And you can run them in the browser if you want to)
1
u/Ravindra__111 Jul 16 '24
Use Intellij and add necessary javafx jars to libraries. Then you will get an option to create a project from scratch with an option of maven or gradle.
1
u/StarshipSatan Jul 16 '24
If you use intellij idea, you should add necessary dependencies to your pom, so you could use javafx classes in your development process. For running your app you should configure your run configuration with adding jvm args --module-path and --add-modules, for the former you pass link to your javafx sdk, like /opt/path/to/sdk, for the latter you pass list of javafx modules to use, like javafx.controls,javafx.fxml