Class ApplicationUtil


  • public final class ApplicationUtil
    extends Object
    Utility class to initialize an application
    • Method Detail

      • getThisApplicationsPath

        public static String getThisApplicationsPath​(String jarFilename)
        Returns the path of this application
        Parameters:
        jarFilename - Filename of the Jar
        Returns:
        Path
      • getThisApplicationsJarFilename

        public static String getThisApplicationsJarFilename​(Class<?> classInJarFile)
        Returns the filename of this application's Jar File or an empty string, if the filename could not be detected
        Parameters:
        classInJarFile - Class which is in Jar File
        Returns:
        Jar Filename or an empty String
      • compareVersions

        public static int compareVersions​(String v1,
                                          String v2)
        Compares two Version-Strings
        Parameters:
        v1 - First Version-String
        v2 - Second Version-String
        Returns:
        0 or less than 0 or more than 0
      • lockLockFile

        public static boolean lockLockFile​(String strLockFilePath,
                                           String strLockFilename)
        Try to lock the lockfile
        Parameters:
        strLockFilePath - Lockfile Path
        strLockFilename - Lockfile Filename
        Returns:
        True if successful
      • releaseLockFile

        public static boolean releaseLockFile()
        Release lock file
        Returns:
        True if successful, false otherwise
      • getLockFile

        public static FileLock getLockFile()
        Returns:
        FileLock or null
      • deleteOldLogFiles

        public static void deleteOldLogFiles​(int days,
                                             String logFileName,
                                             String logPath)
        Parameters:
        days - Days
        logFileName - Logfile Name
        logPath - Logfile Path
      • initializeSLF4JUncaughtExceptionHandler

        public static void initializeSLF4JUncaughtExceptionHandler()
        Sets the default UncaughtExceptionHandler to a handler, which logs exceptions to SLF4J
      • logApplicationInfo

        public static void logApplicationInfo()
        Logs application info
      • writeBasicErrorLogfile

        public static void writeBasicErrorLogfile​(File file,
                                                  String errorMessage)
        Writes an error logfile for the case when no Loggers are initialized. If an Exception occurs while writing the file, the Stacktrace is printed to the console.
        Parameters:
        file - File
        errorMessage - Error Message
      • deleteOldBackupFiles

        public static void deleteOldBackupFiles​(File folder,
                                                String filename,
                                                int daysToKeepBackup)
        Deletes old backup files
        Parameters:
        folder - Folder
        filename - Filename
        daysToKeepBackup - Days to keep backups
      • createInvisibleFrame

        public static JFrame createInvisibleFrame​(String title)
        Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbar
        Parameters:
        title - Window Title
        Returns:
        Invisible Frame
      • createInvisibleFrame

        public static JFrame createInvisibleFrame​(String title,
                                                  Image icon)
        Create invisible frame, which can be used as parent for JOptionPane dialogs, so that the message is displayed in the taskbar
        Parameters:
        title - Window Title
        icon - Icon
        Returns:
        Invisible Frame
      • formatStackTrace

        public static String formatStackTrace​(Throwable throwable)
        Format Stacktrace to String
        Parameters:
        throwable - Throwable
        Returns:
        Stacktrace as String