Password4j/password4j

Properties file location

saprophagist opened this issue · 3 comments

Describe the bug
If developing out of maven and project structure is not "/src/main/resources/.." properties file can't be found. Also can't set path manually.

To Reproduce
Develop a simple application with Netbeans (Ant build) and try to run.

Expected behavior
Load properties as defined in properties file.

Environment:

  • OS: Windows 10
  • JDK OpenJDK 11.0.2
  • Version 1.3.1

Additional context
Project structure:

  • project root
    |
    • resources (x/y/z/abc.properties)
      |
    • src (...)
      |
    • test
      (etc.)

Hi @saprophagist,
thanks for opening this issue.

I think it may be useful if the user specifies with a custom Java property the path of the property file.
E.g. users run the application like java -Dpsw4jPropertiesPath=x/y/z/abc.properties ...

You can now set your property file with -Dpsw4j.configuration=/my/path

@saprophagist You can also set that property dynamically in your code (so your users don't have to use the command-line argument) like this (make sure to replace MyCoolApp with your actual class name):

String configurationFileName = Objects.requireNonNull(MyCoolApp.class.getResource("psw4j.properties")).getFile();
File configurationFile = new File(configurationFileName);
System.setProperty("psw4j.configuration", configurationFile.getAbsolutePath());

This does the exact same as declaring the property via the command line. (See the PropertyReader for more info.)

@firaja I strongly suggest to add this piece of information to the project's wiki.