您的位置:首页 > 其它

使用maven profile 指定配置打包

2018-01-11 13:07 567 查看
使用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

或者

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐