I have a jar with a main class that can be executed as: java -jar test.jar
Inside the jar there is something like
public static void main(String[] args) throws IOException {
InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("config.properties");
Properties prop = new Properties();
prop.load(is);
}
I run both:
java -jar test.jar
java -jar test.jar -cp / tmp (where config.properties is located)
java -jar test.jar -cp / tmp / config.properties (obviously it doesn't work, but it gives you an idea of what I'm trying to achieve here)
The code does not work, all three throw NPE, although I put the path of the config.properties file under my $ PATH and $ CLASSPATH.
The fact is that in the end I will put the configuration file in $ {my-config-path} and read / process it correctly. But temporarily, I just want something fast and dirty.
- I DO NOT want to include the properties file in my jar.
- I want to save it from the outside in the way to classes or the way, when I execute the jar, it finds it without problems.