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?
Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.
Profiles modify the POM at build time, and are used to give parameters different target environments (for example, the path of the database server in the development, testing, and production environments).
The profiles/dev/config. properties file contains the configuration that is used in the development environment. The profiles/prod/config. properties file contains the configuration that is used in the production environment.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With