From b92fe59053d1bda51943cf5294cc5a8454025b9e Mon Sep 17 00:00:00 2001 From: David Harper Date: Wed, 29 Dec 2021 09:24:00 +0000 Subject: [PATCH 1/3] Add simple app runner script. --- build.gradle | 11 ++++++++++- runapp.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100755 runapp.sh diff --git a/build.gradle b/build.gradle index 7d0f00e..9266689 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ plugins { /* run { jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=*:5005' - standardInput = System.in + standardInput = System.in }*/ mainClassName = 'com.jenkov.javafx.ExampleRunnerFromMaven' @@ -41,3 +41,12 @@ javafx { dependencies { } + +task extlibs(type: Copy) { + group 'distribution' + description 'Imports external JAR dependencies.' + from configurations.runtimeClasspath.findAll { it.name.endsWith('jar') } + into "$buildDir/extlibs" +} + +build.dependsOn extlibs diff --git a/runapp.sh b/runapp.sh new file mode 100755 index 0000000..f49d608 --- /dev/null +++ b/runapp.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ $# -lt 1 ] +then + echo "Usage: $0 classname [args]" + exit 1 +fi + +BASEDIR=`dirname $0` + +CLASSDIR=${BASEDIR}/build/classes/java/main + +if [ ! -d "${CLASSDIR}" ] +then + echo "Class directory ${CLASSDIR} not found. Run 'gradle build' then re-run." + exit 1 +fi + +MODULEDIR=${BASEDIR}/build/extlibs +MODULELIST='javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web' + +if [ ! -d "${MODULEDIR}" ] +then + echo "External JAR library directory ${JARLIBDIR} not found. Run 'gradle build' then re-run." + exit 1 +fi + +java -cp ${CLASSDIR} --module-path "${MODULEDIR}" --add-modules "${MODULELIST}" "$@" From 057b834555bbb9d9f998933ce05899a8cbc2a86c Mon Sep 17 00:00:00 2001 From: David Harper Date: Wed, 29 Dec 2021 09:36:10 +0000 Subject: [PATCH 2/3] Add explanation of wrapper script. --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 6d4ebf6..c488cb8 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This repository contains a growing collection of JavaFX examples. So far this Gi I have plans to add lots more examples in the future, so make sure you star this repository for future reference ;-) -The lists of examples is found here: +The lists of examples is found here: - [JavaFX Basic Examples](#javafx-basic-examples) - [JavaFX Advanced Examples](#javafx-advanced-examples) @@ -12,22 +12,23 @@ The lists of examples is found here: The examples come from my JavaFX tutorial series: [JavaFX Tutorial](http://tutorials.jenkov.com). ## Java + JavaFX Version Used -In general the examples in this repository will attempt to use the latest version of Java and JavaFX. +In general the examples in this repository will attempt to use the latest version of Java and JavaFX. For now the examples are tested with Java 14 and JavaFX 14 (yes, 15 + 15 are latest - will update soon!). ## Running the Examples -There are 3 options to run the examples. +There are several options to run the examples. - Using your IDE (IntelliJ IDEA / Eclipse / Netbeans) - Using Maven - passing main class to run on the command line - Using gradle - passing main class to run on the command line - Using Maven - configuring the main class inside the pom.xml +- Using the wrapper script Some of these are covered in more detail below. ### Run the Examples in IntelliJ Idea(needs pre-downloaded javafx modules) To run the examples from within IntelliJ IDEA you must first create a new project in IntelliJ, and set the root -directory to the directory into which you have cloned this Git repository. +directory to the directory into which you have cloned this Git repository. Second, you must download JavaFX and unzip the distribution to some directory. @@ -63,9 +64,13 @@ You can use Maven and edit the pom.xml file and change "mainClass" of openjfx pl ./mvnw clean javafx:run +### Run via the wrapper script +The wrapper script runapp.sh can be used on Linux or macOS hosts. For example to run WebViewExample you can run + +./runapp.sh com.jenkov.javafx.webview.WebViewExample ## Suggestions -If you have any suggestions for missing examples, create a GitHub issue in this repo, and / or ping me on +If you have any suggestions for missing examples, create a GitHub issue in this repo, and / or ping me on Twitter (@jjenkov) or LinkedIn (Jakob Jenkov). @@ -146,7 +151,7 @@ Twitter (@jjenkov) or LinkedIn (Jakob Jenkov). - WebView Examples - [WebView Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewExample.java) - [WebView JavaScript Integration Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewJavaScriptIntegrationExample.java) - - [WebView Mouse Wheel Zoom Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewMouseWheelZoomExample.java) + - [WebView Mouse Wheel Zoom Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/webview/WebViewMouseWheelZoomExample.java) (Mouse wheel zoom code provided by Friedhold Matz (@FriedholdMatz on Twitter)) - 2D Examples - [2D Basics Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/gfx2d/Gfx2DExample.java) @@ -164,5 +169,3 @@ Twitter (@jjenkov) or LinkedIn (Jakob Jenkov). # JavaFX Advanced Examples - [Auto-responsive Layout Example](https://github.com/jjenkov/javafx-examples/blob/main/src/main/java/com/jenkov/javafx/layout/AutoResponsiveLayoutExample.java) - - From d9e0bec21ed291591e6f295f6b05e424c3d7fe55 Mon Sep 17 00:00:00 2001 From: David Harper Date: Wed, 29 Dec 2021 10:23:58 +0000 Subject: [PATCH 3/3] Fix error in variable name. --- runapp.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runapp.sh b/runapp.sh index f49d608..38f189a 100755 --- a/runapp.sh +++ b/runapp.sh @@ -21,7 +21,7 @@ MODULELIST='javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media if [ ! -d "${MODULEDIR}" ] then - echo "External JAR library directory ${JARLIBDIR} not found. Run 'gradle build' then re-run." + echo "External JAR library directory ${MODULEDIR} not found. Run 'gradle build' then re-run." exit 1 fi