I use this code in my program to load a properties file:
Properties properties = new Properties();
URL url = new App().getClass().getResource(PROPERTIES_FILE
There are two workarounds:
Don't use the JAR as executabele JAR, but as library.
java -cp .;filename.jar com.example.YourClassWithMain
Obtain the root location of the JAR file and get the properties file from it.
URL root = getClass().getProtectionDomain().getCodeSource().getLocation();
URL propertiesFile = new URL(root, "filename.properties");
Properties properties = new Properties();
properties.load(propertiesFile.openStream());
None of both are recommended approaches! The recommend approach is to have the following entry in JAR's /META-INF/MANIFEST.MF file:
Class-Path: .
Then it'll be available as classpath resource the usual way. You'll really have to instruct Maven somehow to generate the MANIFEST.MF file like that.