I am developing a custom maven plugin. When I read my properties file of custom plugin everything is well however when I run it at different project as a plugin how can I get that projects properties file, it always looks at resources directory of itself as usual because of:
I have that:
Properties allProperties = new Properties();
allProperties.load(this.getClass().getResourceAsStream("/tokens.properties"));
and I tried that:
Properties allProperties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
allProperties.load(loader.getResourceAsStream("/tokens.properties"));
but didn't work. Any ideas?
PS: When I run it it reads from plugins properties file. My properties files are under
src/main/resources
I use that at my poms:
<build>
...
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
and my properties file:
project.version = ${project.version}
Properties allProperties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
allProperties.load(loader.getResourceAsStream("/tokens.properties"));
You were close. That's indeed the right class loader, but the wrong path. Remove the leading slash.
allProperties.load(loader.getResourceAsStream("tokens.properties"));