How can I run a Maven webapp in Eclipse when I use profiles to populate properties files at build time?

十年热恋 提交于 2019-12-03 06:53:07

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/669639/how-can-i-run-a-maven-webapp-in-eclipse-when-i-use-profiles-to-populate-properti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!