diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md index 53bbd0a..fd4dd74 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,50 @@ Example Maven Project for a JavaFX Application. -Maven modules are configured so that even Images are build (including JPackage app-image). +**The application is no longer a modular application so there are no problems with dependencies that are not providing a +module-info.** -Project includes PMD and spotbugs! +This projects includes multiple plugins: +- Static code analysis with PMD and Spotbugs +- Check of dependency updates during build +- Build of an App-Image using JPackage +- JavaFX plugin to start application + +**Important** All commands following should be issued in the root directoy of the project (the directory where you find the pom.xml) + +*Quick Start* + +- Simply download a zip file of this project and unzip it somewhere on your computer +- open the opm.xml and change the settings at the start of the document to fit with your project -Branches shows, -- including log4j -- including slf4j -This is just for testing purpose / was requiried during threads in http://java-forum.org. \ No newline at end of file +*How to use this project* + +**build the application** + +To build the application, maven / the maven wrapper can be used. Simply do a +```./mvnw package``` +to build the application. +(simply call mvnw instead of ./mvnw on windows!) + +**Clean up** + +To clean up the project, call +```./mvnw package``` + +**Start the application from commandline** +```./mvnw javafx:run``` + +**Build the Image** + +To build the image, the profile Image must be used: +```./mvnw -DImage install``` + +**Important** You cannot build an image using the javafx plugin. The javafx plugin would require that you build a modular +Java application and all dependencies providing a module description. + +**Static code analysis** + +The static code analysis is done when you build the application. The results can be found in +- ./target/pmx.xml +- ./target/spotbugsXml.xml diff --git a/pom.xml b/pom.xml index e7c72ea..9be91a1 100644 --- a/pom.xml +++ b/pom.xml @@ -17,17 +17,17 @@ ${project.artifactId} ${project.artifactId} ${project.artifactId} - de.kneitzel.JavaFXApp - FXAppModule + de.kneitzel.Main 17 3.6.3 + ${project.artifactId}-${project.version} - 5.9.1 - 1.18.26 19.0.2.1 - 23.1.0 + 24.0.1 + 5.9.3 1.18.26 + 5.3.1 3.2.0 @@ -43,8 +43,9 @@ 1.0.0.RC2 0.1.3 3.16.0 - 6.52.0 + 6.55.0 2.11.0 + 0.0.8 4.7.2.0 4.7.3 @@ -52,10 +53,12 @@ UTF-8 ${java.version} ${java.version} + ${java.version} + org.openjfx javafx-controls @@ -66,12 +69,18 @@ javafx-graphics ${javafx.version} + + org.openjfx + javafx-fxml + ${javafx.version} + org.openjfx javafx-web ${javafx.version} + org.projectlombok lombok @@ -79,6 +88,34 @@ provided + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit.version} + test + + + + + org.mockito + mockito-core + ${mockito.version} + test + + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + + org.jetbrains @@ -87,15 +124,10 @@ compile - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - + ${jar.filename} org.apache.maven.plugins @@ -270,6 +302,15 @@ + + + org.openjfx + javafx-maven-plugin + ${javafx.maven.plugin} + + ${main.class} + + @@ -288,13 +329,13 @@ - org.apache.maven.plugins maven-dependency-plugin ${maven.dependency.plugin} + copy-dependencies package @@ -303,98 +344,69 @@ ${project.build.directory}/modules + runtime false false true + + + + copy + install + + copy + + + ${project.build.directory}/modules + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + ${project.build.finalName}.jar + + + true + + - - - org.moditect - moditect-maven-plugin - ${moditect.maven.plugin} - - - add-module-info-to-dependencies - package - - ${project.build.directory}/modules - true - - - - - ${main.class} - ${project.build.sourceDirectory}/module-info.java - - - - --ignore-missing-deps - - - - add-module-info - - - - create-runtime-image - package - - create-runtime-image - - - - ${project.build.directory}/modules - - - ${main.module} - - - ${launcher} - ${main.module} - - 2 - true - APP_WITH_DEPENDENCIES - true - ${project.build.directory}/jlink-image - - - - - - com.github.akman jpackage-maven-plugin ${jpackage.maven.plugin} + + ${appName} + IMAGE + + + + + javafx\..* + + + + + + javafx.controls + javafx.graphics + javafx.fxml + javafx.web + + ${main.class} + ${project.build.directory}/modules + ${jar.filename}.jar + - package + install jpackage - - ${appName} - IMAGE - ${project.build.directory}/jlink-image - ${main.module}/${main.class} - @@ -403,5 +415,4 @@ - diff --git a/src/main/java/de/kneitzel/JavaFXApp.java b/src/main/java/de/kneitzel/JavaFXApp.java index 2273df7..b477580 100644 --- a/src/main/java/de/kneitzel/JavaFXApp.java +++ b/src/main/java/de/kneitzel/JavaFXApp.java @@ -1,30 +1,30 @@ package de.kneitzel; import javafx.application.Application; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.scene.layout.StackPane; import javafx.stage.Stage; +import java.io.IOException; + public class JavaFXApp extends Application { @Override public void start(Stage primaryStage) { - primaryStage.setTitle("Hello World!"); - Button btn = new Button(); - btn.setText("Say 'Hello World'"); - btn.setOnAction(e -> System.out.println("Hello World!")); - - StackPane root = new StackPane(); - root.getChildren().add(btn); - primaryStage.setScene(new Scene(root, 300, 250)); - primaryStage.show(); + try { + primaryStage.setTitle("Hello World!"); + FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainWindow.fxml")); + Parent root = fxmlLoader.load(); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } catch (Exception ex) { + System.out.println("Exception: " + ex.getMessage()); + ex.printStackTrace(); + } } public static void main(String[] args) { - launch(args); + launch(args); } - } diff --git a/src/main/java/de/kneitzel/MainWindow.java b/src/main/java/de/kneitzel/MainWindow.java new file mode 100644 index 0000000..4398a1b --- /dev/null +++ b/src/main/java/de/kneitzel/MainWindow.java @@ -0,0 +1,30 @@ +package de.kneitzel; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Button; +import javafx.scene.control.TextField; + +import java.net.URL; +import java.util.ResourceBundle; + +public class MainWindow implements Initializable { + + @FXML + private TextField textField; + public Button button; + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + if (button == null) { + textField.setText("Button is null"); + } else { + textField.setText("Button is not null"); + } + } + + @FXML + private void onButtonClick(ActionEvent actionEvent) { + + } +} diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java deleted file mode 100644 index ca1dc44..0000000 --- a/src/main/java/module-info.java +++ /dev/null @@ -1,9 +0,0 @@ -module FXAppModule { - requires javafx.base; - requires javafx.graphics; - requires javafx.controls; - requires javafx.web; - - exports de.kneitzel; - opens de.kneitzel; -} diff --git a/src/main/resources/de/kneitzel/MainWindow.fxml b/src/main/resources/de/kneitzel/MainWindow.fxml new file mode 100644 index 0000000..07c63e6 --- /dev/null +++ b/src/main/resources/de/kneitzel/MainWindow.fxml @@ -0,0 +1,11 @@ + + + + + + + +