Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set KeyStore and trustStore path within a jar

I have keystore and truststore files which i want to keep inside a executable jar. In IDE i put these file in a /main/resources/ and was getting a path from there by using ClassLoader, But within a jar file can only be load as a stream. Is there any possibility to get a path of these file as i need to create it SslContextFactory which only get a absolute path rather than a stream?

like image 459
user565 Avatar asked Feb 02 '26 03:02

user565


1 Answers

I think there is no other way rather than create a temp file and delete deleteOnExit() using commons-io.

public static File stream2file(InputStream in, String PREFIX) throws IOException {
    final File tempFile = File.createTempFile(PREFIX, ".jks");
    tempFile.deleteOnExit();
    try (FileOutputStream out = new FileOutputStream(tempFile)) {
        IOUtils.copy(in, out);
    }
    return tempFile;
}
like image 197
user565 Avatar answered Feb 04 '26 17:02

user565



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!