其实也是最近才看Maven, 以前都是用ant+ivy, 对于轻量级的项目来说足够了, 而且非常灵活.
看了看Maven, 约定.... 现在编程都说约定, 约定是挺好, 问题是超出约定的事情太多了, 到头来还要依赖其他东西, 真不想用maven啊.
以前我们开发环境和生产环境的配置文件都是单独分开目录存放的, ant脚本搞个变量就自动打包不同的文件了. 我觉得管理起来也很容易, 所以看到很多maven为解决开发/生产环境的方案真是不太理解啊:
1. 什么 ${your.configuration}, 和spring的东西都差不多了, 配置写到脚本里去了,....这叫啥配置...
2. 调用ant....
还是根据我以前的思路:
src/main目录下原来有 java, resources, 我新建几个目录: resources-dev, resources-test, resources-prod.
resources --- 一些共享的配置文件, 一般不需要修改的
resources-dev --- 开发环境下用的配置文件, 和resources目录下文件没有重合.
resources-prod --- 生产环境下用的配置文件, 和resources目录下文件没有重合.
本机开发的时候设置源码目录为 java, resources, resources-dev, 可以直接开发调试.
编译的时候希望maven根据不同环境, 打包不同的目录下的文件, 我们利用maven的profile和build-helper-maven-plugin插件就可以实现.
<profiles>
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/main/resources_dev</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<classifier>dev</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>test</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId&g