`

maven打包案例-spring boot

阅读更多

打包命令

进入项目的根目录执行maven打包命令

mvn -DskipTests -Ptest clean assembly:assembly

其中,

-DskipTests 是指,忽略测试,如果想执行测试,就不需要加

-Ptest -P后面是指定环境,可选的值有(devtestqaalphabeta 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>

 

分享到:
评论

相关推荐

    新手必看-spring boot 多模块案例

    Gradle的`bootJar`或`war`任务,以及Maven的`spring-boot-maven-plugin`插件可以帮助完成打包。 7. **集成测试**: 使用Spring Boot的`@SpringBootTest`注解进行集成测试,可以测试整个应用或特定模块。对于多模块...

    spring-boot-parent.rar

    在本案例中,我们讨论的是 "spring-boot-parent.rar" 文件,这很可能是某个开发者分享的一个关于Spring Boot父子项目构建的示例或模板。 "spring-boot-parent" 这个名称暗示了这是一个Maven或Gradle的父项目,通常...

    springboot实现maven打包加载不同环境的方式二

    当前案例中包含一整套的代码和word文档,非常适合新手... 主要是通过maven打包加载不同环境的properties文件 然后将对于的属性绑定到指定的实体对象中;然后通过调用接口可以看到加载不同环境控制台打印的内容是不一样的

    maven-spring 实例

    使用Maven打包出的JAR或WAR文件可以直接部署到应用服务器,如Tomcat、Jetty等。 综上所述,"maven-spring 实例"是一个关于如何使用Maven管理项目,并结合Spring框架进行开发的示例。通过这个案例,开发者可以学习...

    自定义spring-boot-starter封装

    当功能完善后,可以将`example-spring-boot-starter`打包成jar,发布到私有Maven仓库或公开的Maven Central,供其他项目使用。 自定义`spring-boot-starter`不仅可以封装通用功能,还可以帮助我们遵循约定优于配置...

    spring boot 简单案例下载

    例如,`spring-boot-starter-web` 可以启动一个基础的 Web 应用,`spring-boot-starter-data-jpa` 则用于数据库操作。 2. **嵌入式服务器**:Spring Boot 支持嵌入式 Tomcat、Jetty 或 Undertow 服务器,这意味着你...

    Spring Boot-实战

    《Spring Boot-实战》这本书是针对Java开发人员的一份实用指南,主要聚焦于Spring Boot框架的应用与实践。Spring Boot是Spring生态系统中的一个关键组件,它旨在简化Spring应用程序的初始搭建以及开发过程,使得...

    spring-boot中文手册

    - 建议读者进一步探索Spring Boot的高级特性和实践案例。 #### 三、使用Spring Boot - **构建系统** - **依赖管理**:解释了如何管理项目中的依赖项。 - **Maven** - **继承starter parent**:说明如何使用...

    Spring-boot 入门案例

    在 Maven 或 Gradle 项目中添加相应的依赖,如 `spring-boot-starter-web`,即可开启 Web 开发支持。 ### 3. 编写主程序 Spring Boot 的入口点是标记为 `@SpringBootApplication` 的类,通常命名为 `Application`...

    spring boot实现的一个小案例

    - `MyBatis-Spring-Boot-master`可能包含了项目的基本结构,如`src/main/java`下包含源代码,`src/main/resources`下有配置文件和Mapper XML文件,`pom.xml`是Maven的构建文件。 通过这个小案例,初学者可以了解...

    Spring Boot2企业应用实战

    8. **安全控制**:通过`spring-boot-starter-security`,Spring Boot提供了基本的安全管理功能,包括身份验证和授权,可以快速搭建安全的Web应用。 9. **测试**:Spring Boot提供了方便的测试支持,包括`@...

    Maven构建springBoot Demo案例

    本篇将详细讲解如何使用Maven来构建一个Spring Boot的Demo案例。 首先,我们需要了解Maven的基本结构,即著名的"Maven目录规范"。一个标准的Maven项目包括`src/main/java`(源代码)、`src/main/resources`(资源...

    Java_Apache Camel Spring Boot示例.zip

    在"camel-spring-boot-examples_main.zip"中,我们可以期待找到以下关键组件和示例: 1. **路由配置**:包含Camel路由的Java或XML配置文件,展示了如何定义路由规则和中间件。 2. **Camel组件**:可能包含了多个...

    springboot+myabtis+maven+swagger

    在这个项目中,开发人员可能已经将Spring Boot与MyBatis集成,实现了数据库操作,利用Maven进行项目构建和依赖管理。同时,Swagger被用来创建API的定义,提供清晰的接口文档,方便其他开发者理解和使用提供的服务。...

    Maven实战(包括安装、配置及使用)

    - Maven支持项目的生命周期管理,使得项目从编译、测试、打包、部署等一系列过程自动化。 - **Maven与极限编程:** - Maven的设计原则与极限编程(XP)的理念相吻合,它强调自动化和简洁的项目管理方式。 #### 二...

    spring-boot-cli-2.1.18.RELEASE-bin.zip

    标题中的"spring-boot-cli-2.1.18.RELEASE-bin.zip"表明这是一个Spring Boot的命令行接口(CLI)的二进制发行版,版本号为2.1.18.RELEASE。Spring Boot是一个由Pivotal团队提供的开源框架,它简化了创建独立的、生产...

    使用maven将Java程序打包成exe文件并制作成Windows系统服务(三)之springboot+nssm生成系统服务

    在本教程中,我们将深入探讨如何使用Maven和NSSM(Non-Sucking Service Manager)将一个Spring Boot应用程序打包成可执行的(exe)文件,并在Windows操作系统中将其配置为系统服务。这一过程对于那些希望在后台无...

    Spring Boot核心技术-笔记

    本篇笔记将介绍Spring Boot的核心概念、微服务架构、环境准备、入门案例以及相关开发工具的配置方法。 1. Spring Boot简介 Spring Boot是由Pivotal团队提供的开源框架,它使用“约定优于配置”的原则,旨在简化...

    spring boot 案例

    testImplementation 'org.springframework.boot:spring-boot-starter-test' } ``` #### 知识点二:使用 Redis 进行缓存 **描述:** Redis 是一种高性能的键值存储系统,常用于缓存数据以提高应用程序性能。...

Global site tag (gtag.js) - Google Analytics