I am trying to refer to a file inside a maven project structure. Through my test cases the file is located successfully, but when I deploy the project to a weblogic environment, I am receiving an error:
java.io.FileNotFoundException: keystore.jks (The system cannot find the path specified)
In my code I am referring to the file as follow:
File pKeyFile = new File("certificates/keystore.jks");
String pKeyPassword = keyStorePassword;
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream keyInput = new FileInputStream(pKeyFile);
Update:
I tried the following:
File pKeyFile = new File(this.getClass().getClassLoader().getResourceAsStream("certificates/keystore.jks").toString());
String pKeyPassword = keyStorePassword;
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream keyInput = new FileInputStream(pKeyFile);
keyStore.load(keyInput, pKeyPassword.toCharArray());
keyInput.close();
keyManagerFactory.init(keyStore, pKeyPassword.toCharArray());
When I evaluated the this.getClass().getClassLoader().getResourceAsStream("certificates/keystore.jks") expression, I could see that the file was found. But it still threw the same error when it tried to load the file as an InputStream.