# if there is a setup or something else to be started, do so now
JAVAEXECUTABLE=`find "$TARGET_LOCATION/{{displayName}}.app/Contents" -name "java" -type f`
RUNAFTER_MAINJAR="{{mainJar}}"
RUNAFTER_MAINCLASS="{{mainClass}}"
RUNAFTER_WORKINGDIR="$TARGET_LOCATION/{{displayName}}.app/Contents/Java/{{workingDir}}"

# this is to be inteded with an embedded JRE and existing jars only
if [ ! -z "$JAVAEXECUTABLE" ]; then
	
	# if the directory exists, start the run after
	if [ -e "$RUNAFTER_WORKINGDIR" ]; then
		if [ -z "$RUNAFTER_MAINCLASS" ]; then
			$(cd "$RUNAFTER_WORKINGDIR" && "$JAVAEXECUTABLE" -jar "$RUNAFTER_MAINJAR" )&
		else
			$(cd "$RUNAFTER_WORKINGDIR" && "$JAVAEXECUTABLE" -classpath "$RUNAFTER_MAINJAR" "$RUNAFTER_MAINCLASS" )&
		fi
	else
		echo "Could not fine working direcoty at: '$RUNAFTER_WORKINGDIR'"
	fi
fi
