使用 Maven 为 dev 和 prod 提供不同的配置文件
我必须在开发和生产中使用不同的 log4j.xml 和属性文件。我正在使用 Maven 进行构建和打包。有没有办法让maven通过POM中的可配置maven属性或传递运行时变量来选择dev或prod?
谢谢, 阿比
I have to different log4j.xml and property files which are to be used in Dev and Production. I am using maven for building and packaging. Is there a way I can let maven choose dev or prod by a configurable maven property in POM or passing a run time variable?
Thanks,
Abi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基于 Maven 中的配置文件的想法并不是最好的,因为这会迫使您运行构建几次,这意味着如果您有两个环境,则必须运行构建两次,如果您有更多环境,请考虑一下这一点。
最好的解决方案是使用 Maven-Assembly-Plugin 创建一个一步中针对不同环境的工件集,这些工件将由分类器区分。我在此处制作了一个完整的示例。
The idea based on profiles in Maven is not the best, cause that would force you to run your build a couple of times which means if you have two environments you have to run your build twice if you have more just think about this.
The best solution is to work with the Maven-Assembly-Plugin to create a set of artifacts for the different environments in a single step which will be distinct by the classifier. I have made a complete example here.
是的,使用 Maven 配置文件。
Yes, use Maven profiles.
作为配置文件的替代方案,它允许您在构建过程中选择“dev”或“prod”,您可以考虑使用maven-assemble-plugin 这样你就可以构建“dev”和“prod” “每次构建时都会装配。
As an alternative to profiles, which allows you to choose either "dev" or "prod" during your build, you might consider using the maven-assembly-plugin so that you can build both "dev" and "prod" assemblies every time you build.