How to access the values ​​defined in the profiles (in pom.xml) via the java code


I have a maven project with different profiles set in pom.xml with different values. But I don't know how to access those values set in profile via java code. For example-

My pom.xml:


Java code-

String serviceurl = "http://"<proxyhost>":<proxyPort>/";

In the above java code, i want to use proxy host as & port as 9444 as defined in pom.xml but how to access those values from pom?? I will appreciate your help

You should use the maven filtering feature.

Just add a property file in src/main/resources with some placeholders:


then myvalue should be defined as a property in your pom.xml

Be sure to activate the filter on your resources: