问题描述:

e.g.

<profiles>

<profile>

<id>rofileX</id>

</profile>

</profiles>

The profile could have been activated using -ProfileX, why am I seeing people bother to add in an activation property, e.g.

<profiles>

<profile>

<id>rofileX</id>

<activation>

<property>

<name>oX</name>

</property>

</activation>

</profile>

</profiles>

to allow activation using -DoX?

Is there any reason to use -D insteal of -P? Or you can achieve more things with -D as oppose to -P?

Thank you

网友答案:

One usage of -Dmyproperty instead of -Pmyprofile is to activate several profiles using only one parameter.

Moreover, you can reuse the -Dmyproperty in other parts of your POM, using ${myproperty}.

网友答案:

The property does not necessarily has to be set via the -D maven option, it may also be a system property. So it is possible to switch between profiles without changing the invocation.

[edit] from theMaven documentation:

-D, --define <arg>
Defines a system property

...

Properties defined on the command line are also available as properties to be used in a Maven POM or Maven Plugin
相关阅读:
Top