JavaFX on Raspberry Pi: runfxapp v1.1

I have updated my runfxapp skript:

Feel free to load it: runfxapp 1.1

Please find installation instructions and usage hints in my previous post.

#!/bin/bash 
#
#############################################################
#
# Script: runfxapp
#
# Start JavaFX apps more conveniently.
#
# (c) copyright 2013 Jens Deters, mail@jensd.de, www.jensd.de
#
#############################################################

JAVA_HOME=/opt/jdk1.8.0
JAVA_MAIN=$JAVA_HOME/bin/java
LIBS=/opt/pi4j/lib/*:/opt/lib/*
SCRIPT=$0
EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_ERROR=2
APP_JAR="NO JAR DEFINED"
VERBOSE=n
APP_VERSION=1.1

function usage {
 echo "runfxapp v$APP_VERSION"
 echo "Usage: $(basename $SCRIPT .sh) [-v] [-h] [-j <PATH_TO_JAR>] <MAIN_CLASS>" >&2
 [[ $# -eq 1 ]] && exit $1 || exit $EXIT_FAILURE
}

function check_preconditions {

 if [[ ! -f $JAVA_MAIN ]];then
    echo "Error: Can't find '$JAVA_MAIN'. Please check your JDK installation AND/OR correct 'JAVA_HOME' in: $SCRIPT"
    exit $EXIT_ERROR
 fi

 if [[ ! -f $APP_JAR ]];then
    echo "Error: Can't find application JAR: '$APP_JAR'." 
    exit $EXIT_ERRORR
 fi
}


while getopts ':j:hv' OPTION ; do
 case $OPTION in
 v) VERBOSE=y
 ;;
 h) usage $EXIT_SUCCESS
 ;;
 j) APP_JAR="$OPTARG"
 ;;
 \?) echo "Error: Unknown Option \"-$OPTARG\"." >&2
     usage $EXIT_ERROR
 ;;
 esac
done

shift $(( OPTIND - 1 ))
if (( $# < 1 )) ; then
 echo "Error: MainClass is needed:" >&2
 usage $EXIT_ERROR
fi

check_preconditions

COMMAND="sudo $JAVA_MAIN -Djavafx.platform=eglfb -classpath .:classes:$LIBS:$JAVA_HOME/jre/lib/jfxrt.jar:$APP_JAR $@"

if [[ $VERBOSE = y ]] ; then
 echo "Attempt to execute: $COMMAND"
fi

$COMMAND

exit $EXIT_SUCCESS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>