最后一步項(xiàng)目打包,打包時(shí)要把生產(chǎn)環(huán)境用到的配置信息加入到項(xiàng)目的配置文件中去檬嘀,這時(shí)候就需要區(qū)分開發(fā)環(huán)境和生產(chǎn)環(huán)境了。maven提供了很好的設(shè)置。
Maven設(shè)置
<profiles>
<profile>
<!-- 本地開發(fā)環(huán)境 -->
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
</profile>
<profile>
<!-- 生產(chǎn)環(huán)境 -->
<id>prod</id>
<properties>
<package.environment>prod</package.environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
maven的配置文件增加一節(jié)机错,定義開發(fā)和生產(chǎn)環(huán)境,activation為生產(chǎn)
增加相應(yīng)配置
這里增加一個(gè)profiles文件夾父腕,里面包含dev和prod兩個(gè)文件夾弱匪,每個(gè)文件夾里面都application.properties和logback.xml這兩個(gè)配置文件。
pom.xml中build節(jié)增加打包配置
<build>
<finalName>bdp_05</finalName>
<defaultGoal>compile</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
<warName>bdp_05</warName>
<webResources>
<resource>
<directory>profiles/${package.environment}</directory>
<targetPath>WEB-INF/classes</targetPath>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
這里指定打包資源的路徑為profiles/${package.environment}
執(zhí)行打包
點(diǎn)擊Maven面板的Execute Maven Goal
按鈕,彈出框輸入clean install
萧诫,開始執(zhí)行打包斥难。
打包結(jié)果