#!/bin/bash
# Provide the app information:
#
# APP = name of the generated jar file
# MOD = name of the module in module-info.java
# MODULES = modules to be included in the custom JRE
#
# Reminder: Don't use spaces unless enclosing values in quotes!
#
# Don't use the default-jdk as it creates wrong images. Use the JDK from http://jdk.java.net/11/
# Set up the path where the jar file is
cd /home/eugene/NetBeansProjects/passwords
# Set the name of the main jar file
APP=passwords.jar
# Set the name of the Module-info
MODINFO=Passwords
# The name of the Java Runtime Environment folder
RUNTIME=PasswordsJRE
# The name of the runnable script to launch the app
RUNAPP=passwords
# Path to JDK
JDK=/home/eugene/JAVA/JDK11
JFXMODS=/home/eugene/JAVA/JFXMODS11
JDKBIN=$JDK/bin
# START OF THE SCRIPT
# Remove the obsolete folders
rm -rf mod
rm -rf $RUNTIME
mkdir mod
echo "- Creating module from the app"
$JDKBIN/jmod create --class-path $APP mod/mod.jmod
echo "- Creating custom JRE. Please wait!"
echo
set -o xtrace
$JDKBIN/jlink \
--compress=2 \
--strip-debug \
--no-man-pages \
--no-header-files \
--module-path $JFXMODS:mod \
--add-modules $MODINFO \
--launcher $RUNAPP=$MODINFO \
--output $RUNTIME
set +o xtrace
echo
rm -rf mod
echo "To run the app, go to $RUNTIME/bin folder"
echo
read -n 1 -s -r -p "Press any key to run the app... "
echo
$RUNTIME/bin/$RUNAPP
echo
read -n 1 -s -r -p "Press any key to finish... "
echo
# Remarks
The above script will create a custom JRE with the runnable bash file in the bin directory.
After the creation of the files, you may need to add the following line to the runnable bash file:
```
cd "$(dirname $0)"
```
This will set up the current directory as working directory.
Otherwise, if you run that bash file from outside the directory (e.g. by means of a desktop shortcut), the jvm will use the `$HOME` as its working directory.
Other things that may need to be added are in this [snippet](https://gist.github.com/ekartoyev/0de506769144213d3211e1d394ba7519).
Additionally, if the app requires some additional dll/so files, place them to the `dllpath` directory, and then add the below parameter to the launch line
```
-Djava.library.path=dllpath
```
_Nota Bene:_ This isn't considered a good practice.
# Running the app without custom JRE or installations:
```
$JAVA_HOME/bin/java -p $PATH_TO_FX:. -m MyModuleName
```
**Prerequisits:**
The $PATH_TO_FX must be indicated in the ~/.profile file. For example, as follows:
```
export PATH_TO_FX=/home/eugene/JAVA/JFXSDK11/lib
```
And the jar file with the MyModuleName app should be in the the current directory.