I’m facing a problem of folder with an executable jar.
In fact I want to call
URL keystoreURL = ServerGUI.class.getResource("/resources/keystore");
String keystorePath = keystoreURL.getPath();
System.setProperty("javax.net.ssl.keyStore",keystorePath);
to load a keyStore.
Because setProperty wants a String to access the file.
My resources folder is inside the /src folder of Eclipse.
Everything works when working inside Eclipse but if I want to create an executable jar file, the Path is not correct even if the resources folder also exists.
edit: Another interesting thing when printing the path :
In Eclipse: file:/C:/Users/Xenom/workspace/eBankingRMI/bin/resources/truststore
In jar : jar:file:/C:/Users/Xenom/Desktop/ClientBanking.jar!/resources/truststore
So clearly setProperty can’t read the second one…
There is no guarantee that a resource URL matches an actual file system file. It won’t be the case in a jar or a war most of the time.
If your API absolutely require a file (and AFAIK keystore does), you’ll need to grab that URL and stream it to an actual filesystem file, and then use that to set the property.