John Doe
John Doe

Reputation: 9764

Taking properties from Maven settings.xml file to application context

There are nice SO question and answers about this issue, but these options didn't work for me.

I want to pass variables to app context:

<bean class="blah.blah.Blah" id="blah">
    <property name="first" value="${first.property}"/>
    <property name="second" value="${second.property}"/>
</bean>

I have the following in the Maven's settings.xml file:

<profiles>
    <profile>
      <id>profileId</id>
      <activation>
          <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
          <first.property>first value</first.property>
          <second.property>second value</second.property>
      </properties>

I tried this option (which is a bit strange), it gave no results. Than I added this plugin:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>process-resources</phase>
        <goals>
          <goal>write-project-properties</goal>
        </goals>
        <configuration>
          <outputFile>
            src/main/resources/maven.properties
          </outputFile>
        </configuration>
      </execution>
    </executions>
</plugin> 

And there wasn't any maven.properties files in the project afterwards. If I created empty file, nothing appeared in it. And I tried to do repeat these steps with -PprofileId, it didn't help. Could someone please provide a working code snippet or tell me what do I miss here? Thanks in advance.

Update: I was wrong, properties-maven-plugin works fine.

Upvotes: 0

Views: 3032

Answers (1)

user944849
user944849

Reputation: 14951

It's not clear to me from your question - but if you tried running mvn -PprofileId resources:resources the properties plugin would not run, because the command is executing an individual goal, not a Maven lifecycle phase. What happens if you run mvn -PprofileId process-resources?

Another question, are any other profiles active? activeByDefault does not mean "always active." Per Maven docs "All profiles that are active by default are automatically deactivated when a profile in the POM is activated on the command line or through its activation config." So if you have another profile active, the one with profileId will not be.

Try removing the activation block from that profile and run mvn -PprofileId process-resources.

Upvotes: 1

Related Questions