打包命令
进入项目的根目录执行maven打包命令
mvn -DskipTests -Ptest clean assembly:assembly
其中,
-DskipTests 是指,忽略测试,如果想执行测试,就不需要加
-Ptest -P后面是指定环境,可选的值有(dev,test,qa,alpha,beta, production 分别代表 开发环境,测试环境,压测环境,集成环境,内测环境,正式环境) 必须指定
pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.lee</groupId> <artifactId>demo</artifactId> <version>1.2.2</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> </parent> <distributionManagement> <repository> <id>${repository.id}</id> <name>lee Repository</name> <url>${repository.url}</url> <layout>default</layout> </repository> </distributionManagement> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <repository.id>lee</repository.id> <repository.url>http://......</repository.url> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.0.19</version> </dependency> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>4.1</version> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>com.github.jsqlparser</groupId> <artifactId>jsqlparser</artifactId> <version>0.9.5</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.53</version> </dependency> <dependency> <groupId>com.opencsv</groupId> <artifactId>opencsv</artifactId> <version>3.8</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.9</version> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.3</version> <exclusions> <exclusion> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> </exclusion> </exclusions> </dependency> </dependencies> k <build> <finalName>demo-${project.version}-${env}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <!-- 打包zip --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assemble/package.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>dist-assembly</id> <phase>install</phase> <goals> <goal>assembly</goal> </goals> <configuration> <encoding>UTF-8</encoding> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assemble/package.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> <!-- 发布zip到私服 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <configuration> <artifacts> <artifact> <file>target/demo-${project.version}-${env}.zip</file> <type>zip</type> <classifier>${env}</classifier> </artifact> </artifacts> </configuration> <executions> <execution> <id>attach-artifact</id> <phase>install</phase> <goals> <goal>attach-artifact</goal> </goals> <configuration> <artifacts> <artifact> <file>target/demo-${project.version}-${env}.zip</file> <type>zip</type> <classifier>${env}</classifier> </artifact> </artifacts> </configuration> </execution> </executions> </plugin> </plugins> </build> <profiles> <!-- 默认的开发环境 --> <profile> <id>dev</id> <properties> <env>dev</env> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> </resource> <resource> <directory>${project.basedir}/src/main/config/${env}</directory> </resource> </resources> </build> </profile> <!-- 测试环境 --> <profile> <id>test</id> <properties> <env>test</env> </properties> <build> <resources> <resource> <!-- 这里配置的是一个不存在的路径,防止配置文件打包到jar中去 --> <directory>${project.basedir}/src/main/resources2</directory> </resource> </resources> </build> </profile> <!-- 压力测试环境 --> <profile> <id>qa</id> <properties> <env>qa</env> </properties> <build> <resources> <resource> <!-- 这里配置的是一个不存在的路径,防止配置文件打包到jar中去 --> <directory>${project.basedir}/src/main/resources2</directory> </resource> </resources> </build> </profile> <!-- 集成环境 --> <profile> <id>alpha</id> <properties> <env>alpha</env> </properties> <build> <resources> <resource> <!-- 这里配置的是一个不存在的路径,防止配置文件打包到jar中去 --> <directory>${project.basedir}/src/main/resources2</directory> </resource> </resources> </build> </profile> <!-- 内测环境 --> <profile> <id>beta</id> <properties> <env>beta</env> </properties> <build> <resources> <resource> <!-- 这里配置的是一个不存在的路径,防止配置文件打包到jar中去 --> <directory>${project.basedir}/src/main/resources2</directory> </resource> </resources> </build> </profile> <!-- 生产环境 --> <profile> <id>production</id> <properties> <env>production</env> </properties> <build> <resources> <resource> <!-- 这里配置的是一个不存在的路径,防止配置文件打包到jar中去 --> <directory>${project.basedir}/src/main/resources2</directory> </resource> </resources> </build> </profile> </profiles> </project>