Building two different versions a given war with maven profiles and filtering from eclipse

断了今生、忘了曾经 提交于 2019-12-02 16:16:27

问题


I am trying to use maven profiles and filtering in order to produce two different versions of a given web archive (war):

  1. A first one for local deployment to my local machine on localhost
  2. A second one for remote deployment to cloudfoundry

There are a number of properties that differ according to whether the app is deployed to my local machine or to cloudfoundry.

Of course the difficult bit is that I am trying to do all this from STS/Eclipse and deploy from Eclipse to my local tomcat and to cloudfoundry...

Can anyone please provide advice, tips or suggestions?


回答1:


If you are using Spring versioning 3.1+ the "profile" attribute for <beans> in the spring bean configuration xml would be the best choice. Take a look at the doc here: http://docs.cloudfoundry.com/frameworks/java/spring/spring.html#using-spring-profiles-to-conditionalize-cloud-foundry-configuration

Basically you need to specify at least 2 elements. One for your local properties (profile="default") and one for the properties when deployed to CF. The latter one should be defined as <beans profile="cloud">. When running locally the properties within "cloud" would be ignored and properties in "default" will take effect. When pushed to CF, CF will detect the profile named "cloud" and, which is better, inject corresponding datasource connection info of the services provisioned by CF itself. You can find the detailed CF-specified properties in that doc as well.

For more information about the profile attribute, see the doc here: http://blog.springsource.com/2011/02/11/spring-framework-3-1-m1-released/




回答2:


Consider having a single project per artifact generated. Hence one project generating your local deployment and one project generating your cloudfoundry deployment.

Overlays (http://maven.apache.org/plugins/maven-war-plugin/overlays.html) is the officially sanctioned way to bake in extra files in an existing WAR file, giving a new WAR artifact. Very useful but may be too slow for comfort while developing.



来源:https://stackoverflow.com/questions/13902703/building-two-different-versions-a-given-war-with-maven-profiles-and-filtering-fr

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