<profiles>
<!--default开发分支-->
<profile>
<id>local</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/local/deploy.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources/common/</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/local/</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<filters>
<filter>src/main/resources/test/deploy.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources/common/</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/test/</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
<includes>
<include>deploy/*</include>
</includes>
<targetPath>${project.build.directory}</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
deploy文件夹下这些文件中的${key}会被替换掉为真正的值
#!/bin/bash
base="${deploy.base}"
name="${project.name}"
java_home="${deploy.java.home}"
bin_home="${deploy.bin.home}"
conf_home="${deploy.conf.home}/resin"
deploy="${deploy.base}"
webapp="${deploy}/${project.name}"
servers=(${deploy.。。.server})
resin="${deploy.resin.home}"
而${deploy.base} ..这些是在deploy.properites中定义
详解
我们分析下<resource>下面的属性
<directory>: 配置那个目录下的文件通过${key}会被替换成属性值,resource目录下,我们一般放jdbc连接,或配置文件
<includes>:指定那个目录下那个文件
<filtering>:这个配置的意思是过滤上面指定属性文件中的占位符,占位符是${变量名称}这样的形式,maven会自动读取配置文件,然后解析其中的占位符,使用上面pom文件中定义的属性进行替换
<exclueds>:在resource目录下,有很多文件,但用些文件不希望替换,则可以通过<excluede>指定
<filters>:这里的filters与<profile>的filter意思一样,都是指属性文件地址,这个如果上面定义<profile>的时候指定了,这里就不需要了,但有些开发习惯是在<profile>不定义,然后在<build>里指定。
在dispather-servlet下
<context:component-scanbase-package="com.。。。.webapp"/>
<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<list>
<value>classpath:dubbo.properties</value>
</list>
</property>
</bean>
只有简单配置这些,在使用maven命令的时候 mvn clean package -PprofileId ,就可以根据不同环境打不同的包了