0

My current project profiles in pom.xml are following this.

<profiles>
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>

<profile>
<id>production</id>
</profile>
<profile>
<id>development</id>
</profile>
</profiles>

I am looking for a way to print to check if this build is on local in .java code. I also would like to make some functions divided.


System.out.println(isLocal)
/* When it in local. it should be true*/

if(isLocal)
{
XXX
}
else
{
YYY
}

Project is compiled like "mvn compile -P local" in Eclipse

user2006734
  • 325
  • 5
  • 19
  • Does this answer your question? [Access maven properties defined in the pom](https://stackoverflow.com/questions/11500533/access-maven-properties-defined-in-the-pom) – Giorgi Tsiklauri Aug 19 '20 at 06:25
  • I would like to know how to check whether the project is compiled with -P local... and `local` is defined in pom.xml – user2006734 Aug 19 '20 at 06:29

1 Answers1

0

You probably have to do the following:

  • Define a property inside the profile.
  • Define a properties file in your resources.
  • Use resource filtering to write the property to this properties file.
  • Load the resource in your Java code and check the property within.
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142