views:

1035

answers:

1

I'm trying to build an application starting from an Appfuse Archetype, but I get some strange problems. For once I'd like to use a hsqldb for automated unit tests and integration tests, and a mysql db for my manual testing so that I can easily manipulate the data when I need to, so it would be nice to automatically switch profiles during the testing phases. Is there a way to do that?

+1  A: 

I'm not sure if this is exactly what you are asking for, but you can do the following to setup multiple filters for your Maven project.

<filters>
  <filter>/your/path/filter-${env}.properties</filter>
</filters>

This way you can setup multiple profiles using:

<profiles>
  <profile>
    <id>local</id>
    <properties>
      <env>local</env>
    </properties>
  </profile>
  <profile>
    <id>test</id>
    <properties>
      <env>test</env>
    </properties>
  </profile>
</profiles>

You can then run the build with the relevant property file using:

mvn -P <profile id>

This would require having property files located at:

/your/path/filter-local.properties
/your/path/filter-test.properties
Taylor Leese
While this is certainly a good way to switch property files from maven execution to maven execution I was hoping for something more granular.I want to simply execute mvn clean jetty:runor similar and then resources are filled in with placeholders that come from the test profile, then, once the tests ran through, I'd like to switch automatically to another profile, that will then be used to replace the placeholders and then start the jetty server.Basically I want to run the unit tests on another database configuration :-)
cdecker
I see -- so you want to use different profiles for different phases of the Maven lifecycle? I'm not sure if that is possible, but we'll see if anybody else answers.
Taylor Leese
You can't use different profiles for different phases of the same run. I've bumped into this problem since 2.0.3 days. I get around this with mvn -PlocalTest clean package;mvn -PfullBuild clean package deploy.
sal