I have the following problem: I try to load a file from jar but I have the same file outside situated at the same relative path: "res/rtrconfig" as the file in jar. How can I ignore the outside file and get the jar file path?. I can't delete the outside file because other parts of my code need it. What I've got until now:
ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL url = loader.getResource(path); //check if file is in jar or not if (url == null) { System.err.println("FATAL: Properties file not found.Stopping the server."); System.exit(-1); } if ( !url.getProtocol().equals("jar")){ System.err.println("Properties found outside jars.Please delete " + url.getPath() + " and re-start the server"); System.exit(-1); } This part of code checks if the file is founded in jar or in path. I don't know how to configure URL to look after file in jar before file in path. Thanks for your time.