views:

1285

answers:

2

Here is an example profile in my POM:

    <profiles>
 <profile>
  <id>QA</id>
  <activation>
   <activeByDefault>true</activeByDefault>
  </activation>
  <properties>
   <jdbc.url>jdbc:mysql://127.0.0.1:3306/SomeDB</jdbc.url>
   <jdbc.username>webapp</jdbc.username>
   <jdbc.password>somepassword</jdbc.password>
  </properties>
 </profile>
 ...

I then have a properties file in my resources folder like this:

jdbc.url = ${jdbc.url}
jdbc.username = ${jdbc.username}
jdbc.password = ${jdbc.password}

and finally I turn filtering on in my POM:

    <build>
 <resources>
  <resource>
   <directory>src/main/resources</directory>
   <filtering>true</filtering>
  </resource>
 </resources>
 ...

This is actually a simplified example, but you get the idea. Basically when I run

mvn install -P QA

Maven will filter my app.properties file, replace all the placeholders with the values held in the profile, and deploy the populated properties file.

The problem with all of this is that I like to utilize the Servers mechanism in Eclipse, where I have Tomcat running within the IDE. My projects runs in this instance, and Eclipse takes care of updating, redeploying, etc. Maven is left out of the picture, however, during deployments within the IDE and this properties file never gets populated properly.

So, how can I continue running my project within the IDE, but have this properties file properly populated?

+3  A: 

You can effectively run any Maven command (including ones with profiles) through the m2eclipse plugin. Also, m2eclipse works with WTP (which I believe is where the Servers tab comes from). I'm not certain on this part, but I've used it to deploy web apps to Tomcat within Eclipse for a Maven project.

Alex Miller
+1  A: 

Thanks Alex. I ended up installing Eclipse Integration for Apache Maven (Eclipse IAM), formerly Q for Eclipse

This plugin solved two problems: populating properties files during Publish to Server events in Eclipse and populating the WEB-INF/lib folder. Before, even though I was running mvn eclipse:eclipse to satisfy my Build Path in Eclipse, it was not publishing these dependencies to the embedded servers correctly. This plugin does that. Having solved these two issues, I don't see any other barriers to developing a Maven project in Eclipse using the embedded servers.

rcampbell