`
阿尔萨斯
  • 浏览: 4202977 次
社区版块
存档分类
最新评论

用Maven profile实现不同的打包策略

 
阅读更多

需求是:

1.在本地开发的时候,war包部署在本地glassfish上的时候contextroot是dev-geoflow

2.在持续集成的时候,war包部署在服务器上的glassfish的时候,contextroot是geoflow

3.默认情况下,使用2


首先配置一个用于本地开发的profile

  <profiles>
    <profile>
      <id>dev</id>
      <properties>
	<webXmlPath>webxml/develop</webXmlPath>
      </properties>
    </profile>
  </profiles>

然后配置一个默认的环境变量

  <properties>
    <webXmlPath>webxml/release</webXmlPath>
  </properties>

在项目目录下创建webxml目录,分别有两个子目录develop和release

目录下分别配置了sun-web.xml,contextroot值不一样。


现在在maven-war-plugin上使用变量${webXmlPath}

      <plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-war-plugin</artifactId>
	<version>2.1.1</version>
	<configuration>
	  <webResources>
	    <resource>
	      <directory>${webXmlPath}</directory>
	      <targetPath>WEB-INF</targetPath>
	    </resource>
	  </webResources>
	</configuration>
      </plugin>

好了。当运行mvn package的时候,将webxml/release目录下的xml文件打包到WEB-INF内。这是默认情况。持续集成服务器使用。

当运行mvn package -P dev 的时候,将webxml/develop目录下的xml文件打包的WEB-INF内,这是本地开发使用。




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics