当我使用配置文件在构建时填充属性文件时,如何在Eclipse中运行Maven webapp? [英] How can I run a Maven webapp in Eclipse when I use profiles to populate properties files at build time?

查看:131
本文介绍了当我使用配置文件在构建时填充属性文件时,如何在Eclipse中运行Maven webapp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是POM中的一个示例配置文件:

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>
    ...

然后,我的资源文件夹中有一个属性文件,如下所示: / p>

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

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

最后我在POM中打开过滤器:

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

mvn install -P QA

Maven将过滤我的app.properties文件,用配置文件中保存的值替换所有占位符,并部署填充的属性文件。

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

所有这一切,我喜欢在Eclipse中使用服务器机制,其中我在IDE中运行Tomcat。我的项目在这种情况下运行,Eclipse负责更新,重新部署等。然而,在IDE内的部署过程中,Maven不再出现,并且此属性文件从未被正确填充。

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.

那么,如何继续在IDE中运行我的项目,但这个属性文件是否正确填充?

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

推荐答案

感谢亚历克斯。我最终安装了适用于Apache Maven(Eclipse IAM)的Eclipse集成,以前的Eclipse for Eclipse

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

此插件解决了两个问题:在Eclipse中发布到服务器事件期间填充属性文件,并填充WEB-INF / lib文件夹。以前,即使我正在运行mvn eclipse:eclipse来满足Eclipse中的Build Path,它并不是将这些依赖关系正确地发布给嵌入式服务器。这个插件做到这一点。解决了这两个问题后,我没有看到使用嵌入式服务器在Eclipse中开发Maven项目的其他障碍。

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.

这篇关于当我使用配置文件在构建时填充属性文件时,如何在Eclipse中运行Maven webapp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆