I’m at the final step of developing (and especially deploying) a client server application where I have a secured connection using TLS. I got the keystore and truststore for the client and the server and currently I load them as SystemProperties before creating the SSLSocket / SSLServerSocket like this:
Properties systemProperties = System.getProperties(); systemProperties.put("javax.net.ssl.keyStore", "./auth/labkey.jks"); systemProperties.put("javax.net.ssl.keyStorePassword", "<somepassword>"); systemProperties.put("javax.net.ssl.trustStore", "./auth/labtrust.jks"); systemProperties.put("javax.net.ssl.trustStorePassword", "<somepassword>"); System.setProperties(systemProperties);
This works fine but – as I already thought – doesn’t when packaging everything into a .jar file. Currently my project folder consists of the normal src folder in which I keep all the packages with the sourcecode files. The keystore and truststore are kept in a folder called “auth” which is on the same level as the src folder.
I know from previous projects that the relative path changes when packaging additional files into the .jar however the first thing is I don’t know how I should properly handle these file to have them packed into the .jar (currently they are only included when I create a package for them in the source folder or declare the auth folder as an additional source folder).
I tried both approaches and after testing a lot of different relative paths (which is the second problem: finding the right relative path) I couldn’t figure out how to properly address them.
Any advice or hint would be really appreciated.
After trying out several things in context with suggested ideas I can narrow the problem down to the path to the keystore and truststore file being my actual problem. I’m quite sure if I were able to access it relatively there would be an option to use, however for accessing the files I HAVE to provide a path in any kind, no matter which approach I’m going to use. The fact that I’m not able to get the proper relative path to the file is therefore the main problem which I need to get solved.
So accordingly these questions come to my mind:
- How do I correctly add these files to the .jar?
- Will I need to make the auth folder a source folder or do I need to put it in a package or is there any need or possibility to configure the files correctly by configuring the build path?
- What will then be the relative path to the files?