For fetching the artifactId on my project, I'm using the following code.
public static void main(String[] args) {
Properties prop = new Properties();
InputStream in = null;
try {
String fileName = "application.properties";
in = ConfigServiceApplication.class.getClassLoader().getResourceAsStream(fileName);
prop.load(in);
SpringApplication.run(ConfigServiceApplication.class, args);
System.out.println(prop.getProperty("prop.name");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
My application.properties contains the following:
prop.name=${project.artifactId}
If everything were to run correctly, the expected output is:
config-service //this is my artifactId
but the output that I get when I run the above code is
${project.artifactId}
I have referenced these links for fetching the information: Retrieve version from maven pom.xml in code, http://www.mkyong.com/java/java-properties-file-examples/
Can anyone correct my code to correctly fetch the artifactId?
Edit: Pom file:
<project>
...
<artifactId>config-service</artifactId>
...
<properties>
<name>${project.artifactId}</name>
</properties>
...
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
...
</project>