0

I have a keystore that is located on the top level of my .jar file. To build a TLS SSLSocket from it I need to set it as SystemProperty using

Properties systemProperties = System.getProperties();
systemProperties.put("javax.net.ssl.keyStore", "<relative Path to File>");
systemProperties.put("javax.net.ssl.keyStorePassword", "<password>");
System.setProperties(systemProperties);

My class file from which this code is being executed sits here in the .jar file:

server.jar
|
|-com
|  |-organization
|         |-application
|                |-frontend
|                     |-Server.class <-- This needs the keystore
|
|-keystore.jks <-- this is the keystore

I already tried a lot of different paths however none of them worked until now. When running the application in Eclipse my current (and working) relative path is "./auth/labkey.jks" as "auth" is a folder which resides on the same file hierarchy level as the src folder in which the code is stored.

I would be really grateful for any tips on how the relative path I need to use should look like. I'm well aware that there apparently is the possibility to use ClassLoader to access this file properly, however my problem is not the loading process but rather that I can not refer to the file (which I also need to do when using ClassLoader), so suggesting that I should use ClassLoader is not helping me solve the main problem at this point.

Samaranth
  • 385
  • 3
  • 16
  • `"...so suggesting that I should use ClassLoader is not helping me solve the main problem at this point."` -- then I don't see that there is a viable solution since files do not exist within a jar, and instead, you *should* be retrieving the data as a resource with the class loader. – Hovercraft Full Of Eels Aug 03 '19 at 15:55
  • You should consider moving the file so that it is reachable by the class loader – Hovercraft Full Of Eels Aug 03 '19 at 15:56
  • The thing is that I know there is the option of using a ClassLoader. I just don't know how to set up the path to it, so saying I should use ClassLoader instead of the SystemProperties doesn't help me because I need a correct relative path (that I'm currently missing) either way. I just want to stress that the relative path is what I need to get. – Samaranth Aug 03 '19 at 15:59
  • After much fiddling around I was able to get a working solution. As it is apparently not possible to load the keystore / truststore properly using ClassLoader the only possibility to access it seems to be to put it in a fixed location on the harddrive and access it there providing the absolute path like systemProperties.put("javax.net.ssl.keyStore", "C:/Util/auth/keystore.jks"). – Samaranth Aug 03 '19 at 18:39

0 Answers0