package com.alttd.forms.properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.File; import java.util.Optional; public class JarPath { private static final Logger logger = LoggerFactory.getLogger(JarPath.class); public static Optional getCurrentJarDir() { try { String path = JarPath.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); File parentFile = new File(path).getParentFile(); if (!parentFile.isDirectory()) { logger.error("Parent file of jar is not a directory"); return Optional.empty(); } return Optional.of(parentFile); } catch (Exception e) { logger.error("Error getting current jar directory", e); return Optional.empty(); } } }