使用maven profile 指定配置打包
1、配置profiles
<profiles>
<profile>
<!-- 打包環境 -->
<id>hangzhou</id>
<properties>
<!-- 節點名稱 -->
<environment>hangzhou</environment>
<!--強制覆蓋文件-->
<maven.resources.overwrite>true</maven.resources.overwrite>
</properties>
<activation>
<activeByDefault>true</activeByDefault><!-- 默認激活該profile節點-->
</activation>
</profile>
<profile>
<!-- 節點名稱 -->
<id>guangzhou</id>
<properties>
<!-- 節點名稱 -->
<environment>guangzhou</environment>
<!--強制覆蓋文件-->
<maven.resources.overwrite>true</maven.resources.overwrite>
</properties>
</profile>
<profile>
<!-- 節點名稱 -->
<id>haikou</id>
<properties>
<!-- 節點名稱 -->
<environment>haikou</environment>
<maven.resources.overwrite>true</maven.resources.overwrite>
</properties>
</profile>
</profiles>
2、配置resources
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!--排出目錄-->
<exclude>buildconfig/hangzhou/*</exclude>
<exclude>buildconfig/guangzhou/*</exclude>
<exclude>buildconfig/haikouo/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/buildconfig/${environment}</directory>
<!--<targetPath>/</targetPath>-->
<!--不設置targetPath表示直接寫入根目錄-->
</resource>
</resources>
build文件具體代碼
<build>
<finalName>signal-jam</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<!--排出目錄-->
<exclude>buildconfig/hangzhou/*</exclude>
<exclude>buildconfig/guangzhou/*</exclude>
<exclude>buildconfig/haikouo/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/buildconfig/${environment}</directory>
<!--<targetPath>/</targetPath>-->
<!--不設置targetPath表示直接寫入根目錄-->
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
<version>${mybatis-generator.version}</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- do not enable it, this will creates a non standard jar and cause autoconfig to fail -->
<executable>false</executable>
<mainClass>com.aliyun.citybrain.App</mainClass>
</configuration>
</plugin>
</plugins>
</build>
4、輸入命令打包 或 idea maven側邊欄 的package
命令格式爲: mvn package -P配置的節點名稱
如:mvn package -Phangzhou
或者