java - Load resource from anywhere in classpath -


I have a simple Java application that loads the properties file from the existing package.

  this.getClass () getResourceAsStream ("props.properties") .;  

This works fine when I want that the property file is in the current package, however, I want to package this application as a jar and with a new property file defined And want to override where I use it. Is there a way to load the first resource called "props properties" on the classpath?

I want it to be easy to override the properties file through the command line:

  java.exe -classpath props.properties; MyJar.jar com.test.MyApp  

I do not want to open the JAR and modify the properties file to change something. I feel that I am not clear ...

If everything fails, then you two The different file names are called "props-default.properties" to override the command line inside my "jar.jar" and "propsproperties". In your code, you try to load the props.properties file and download the fallback for the pre-defaults.propect if it was not found.


Comments