-
Notifications
You must be signed in to change notification settings - Fork 1
Maven config
We extract version of each dependency into a property:
<properties>
<!-- Base -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Java -->
<javafx.version>20</javafx.version>
<jdk.version>22</jdk.version>
...
<jsoup.version>1.18.1</jsoup.version>
</properties>So when we are declaring a dependency we just need to put property name with $ sign into <version> section:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>We are using maven-shade-plugin to build "fat" JAR (jar with dependencies) and I AM NOT SURE but:
u need to specify <mainClass> tag configuration of this plugin.
For this plugin MainClass SHOULD NOT extend Application.
So we created Launcher class with only one method inside and declared it as a main class in shade plugin:
public class Launcher {
public static void main(String[] args) {
new App().run();
}
}Our App class extends Application and has run and start method methods:
public void run() {
launch();
}@Override
public void start(Stage stage) throws IOException {
dataHandler = new DataHandler();
App.primaryStage = stage;
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1000, 800);
stage.titleProperty().bind(L10N.createStringBinding("appName"));
UserPreferencesManager preferencesManager = new UserPreferencesManager();
ThemeManager themeManager = new ThemeManager(preferencesManager);
// apply saved theme
themeManager.applySavedTheme();
stage.setScene(scene);
stage.show();
}With command mvn dependency:analyze u can print info about your dependencies.
We have found that all javafx dependencies are platform specific (Windows, linux, mac).
[WARNING] Used undeclared dependencies found:
[WARNING] org.openjfx:javafx-fxml:jar:linux:20:compile
[WARNING] org.openjfx:javafx-controls:jar:linux:20:compile
[WARNING] org.openjfx:javafx-graphics:jar:linux:20:compile
[WARNING] org.openjfx:javafx-base:jar:linux:20:compile
If u want to build JAR file for each platform u need to specify <classifier>[platform]</classifier> tag where [platform] is win, mac or linux, but it didn't worked for us so we ended up with following solution: create JAR file on a different OS