I have to deploy a simple .jar
file in a production environment. For security reasons, I'm not able to write production credentials inside the application.properties
.
I retrieve properties like so:
Properties properties = new Properties();
InputStream is = PropertiesLoader.class.getResourceAsStream("/application.properties");
properties.load(is);
Since the .jar
contains /application.properties
at its root directory, it will be read correctly. I need to outsource this application.properties
and I was wondering if there was a way simply by adding a parameter for the java -jar App.jar
command.
I only found parameters for a Spring project (here), which are not for me because this .jar
is plain JDBC Java.
I would like to avoid using a FileInputStream
and giving the file path as parameter, like so:
Properties properties = new Properties();
String applicationPropertiesPath = args[0];
FileInputStream fis = new FileInputStream(applicationPropertiesPath);
properties.load(fis);
And then launching the .jar
with java -jar App.jar /path/to/application.properties
.. But I will, if there are no other options.
The solution I adopted is copying the external application.properties
inside the .jar
file, using this command:
jar uf App.jar /path/to/application.properties
Works flawlessly.