首先创建一个多模块的SpringBoot项目

项目结构

父pom的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<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.shanghai.abcd</groupId>
<artifactId>content-service</artifactId>
<packaging>pom</packaging>
<version>1.0.1-SNAPSHOT</version>
<modules>
<module>web-service</module>
<module>config-service</module>
<module>common-service</module>
<module>biz-service</module>
<module>dal-service</module>
<module>deploy-service</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.9</junit.version>
<java.version>1.8</java.version>
<source.encoding>UTF-8</source.encoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.4.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

  子模块web模块的pom文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>content-service</artifactId>
<groupId>com.shanghai.abcd</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>web-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.shanghai.abcd</groupId>
<artifactId>biz-service</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<finalName>content</finalName>
<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-resources-plugin</artifactId>
<configuration>
<encoding>${source.encoding}</encoding>
</configuration>
</plugin> <!--spring boot 的编译插件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

  web模块中main启动文件

package com.shanghai.abcd.content;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ComponentScan; /**
* @Auther:
* @Date: 2018/5/25 15:26
* @Description: PACKAGE_NAME
*/
@SpringBootApplication
@ConfigurationProperties(value = "classpath:application.properties")
@ComponentScan("com.shanghai.abcd.content")
public class ContentApplication { public static void main(String[] args) {
SpringApplication.run(ContentApplication.class, args);
}
}

  重点是在deploy-service模块,项目的部署文件都是在该模块维护的,文件结构如下:

deploy-service子模块文件结构

deploy模块的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>content-service</artifactId>
<groupId>com.shanghai.abcd</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>deploy-service</artifactId> <build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<finalName>content</finalName>
<appendAssemblyId>false</appendAssemblyId> <!-- 如果只想有finalName,不需要连接release.xml中的id -->
<tarLongFileMode>posix</tarLongFileMode> <!-- 解决tar大小的限制问题 -->
<descriptors>
<descriptor>src/main/assembly/release.xml</descriptor>
</descriptors>
<outputDirectory>../output</outputDirectory>
<attach>false</attach>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> </project>

  release.xml文件:

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>content</id>
<formats>
<format>tar.gz</format>
</formats> <includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!-- 程序运行的jar包 -->
<fileSet>
<directory>../web-service/target/</directory> <!--需要打包的项目文件目录 -->
<outputDirectory>bin</outputDirectory> <!-- 打包后输出的路径,生成bin目录 -->
<includes>
<include>**/*.jar</include>
</includes>
<fileMode>0755</fileMode> <!--文件执行权限-->
</fileSet> <!-- 程序运行的启动脚本 -->
<fileSet>
<directory>target/classes/bin</directory> <!-- 指定要包含的目录,必须是目录 -->
<outputDirectory>bin</outputDirectory> <!-- 打包的文件解压后放在该目录下 -->
<includes>
<include>**/*.sh</include>
</includes>
<fileMode>0755</fileMode> <!--文件执行权限-->
</fileSet>
<fileSet>
<!-- 配置文件 -->
<directory>../config-service/target/classes</directory> <!-- 指定要包含的目录,必须是目录 -->
<outputDirectory>conf</outputDirectory> <!-- 指定当前要包含的目录的目的地 -->
<includes>
<include>**/*.properties</include>
</includes>
<fileMode>0755</fileMode> <!--文件执行权限-->
</fileSet>
</fileSets> <dependencySets>
<!-- 项目的依赖包 -->
<dependencySet>
<outputDirectory>lib</outputDirectory><!-- 依赖jar包放置目录-->
<useProjectArtifact>true</useProjectArtifact> <!-- 当前项目构件是否包含在这个依赖集合里 -->
</dependencySet>
</dependencySets>
</assembly>

  

配置文件是统一放在config-service模块的,该模块的目录结构如下:

config-service模块的目录结构

config模块的pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>content-service</artifactId>
<groupId>com.shanghai.abcd</groupId>
<version>1.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>config-service</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<profiles>
<profile>
<id>dev</id>
<properties>
<environment>dev</environment>
</properties>
<activation>
<activeByDefault>true</activeByDefault> <!-- 默认是dev环境 -->
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<environment>test</environment>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<environment>prod</environment>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<excludes>
<exclude>application-dev.properties</exclude>
<exclude>application-test.properties</exclude>
<exclude>application-prod.properties</exclude>
<exclude>application.properties</exclude>
</excludes>
</resource>
<resource>
<filtering>true</filtering> <!-- 为了能让profiles中的内容能让resources中的文件使用到,需要resources插件将filtering设置为true -->
<directory>src/main/resources</directory>
<includes>
<include>application-${environment}.properties</include>
<include>application.properties</include>
</includes>
</resource>
</resources>
</build>
</project>

  

最后通过 mvn clean package -Pdev命令来打包项目,在项目根目录下生成一个output文件

cd output 后解压该项目:

tar -zxvf content.tar.gz

得到如下目录:

Maven 中maven-assembly-plugin插件的使用笔记 SpringBoot环境的更多相关文章

  1. maven中maven dependencies中依赖出现了项目

    maven 中maven dependencies中依赖出现了项目,把依赖的项目关掉,项目消失,但是还是无法打包 ,出现的错误如图.说明:依赖的项目为project-dao  打包的项目为projec ...

  2. maven中添加jetty运行插件

            maven项目,用jetty插件运行,对热部署的支持比较好.maven的pom文件加入下面代码 <plugin> <groupId>org.mortbay.je ...

  3. maven中经常使用的插件

    tomcat插件:非常实用,特点就是不用配置tomcat,可以任意修改端口号. <plugin> <groupId>org.apache.tomcat.maven</gr ...

  4. maven中可以直接引用的java系统属性和环境变量属性

    一.查看命令: 1 mvn help :system 二.引用 在pom文件中通过 ${变量名}来引用 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...

  5. jenkins中Email Extersion Plugin插件使用说明点

    在jenkins中使用第3方邮件插件Email Extersion Plugin时,根据网上教程,发现每次都没有生成模板 再次查看,发现 $HOME_jenkins下没有templeate文件夹,查阅 ...

  6. java IDE 中安装 lombok plugin 插件,并使用 @Slf4j 注解打印日志初体验

    lombok 插件介绍: IntelliJ IDEA官方插件页面:https://plugins.jetbrains.com/plugin/6317-lombok-plugin 使用lombok之后, ...

  7. 在Eclipse中手动安装pydev插件,eclipse开发python环境配置

    最近在学习Python,因为我是做java的,用惯了eclipse,所以就想用eclipse开发python,但是配置开发环境的时候发现按照网上的配置大多不行,而且都是用的在线安装,很垃圾,没办法,自 ...

  8. 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用

    今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...

  9. Maven中基于POM.xml的Profile来动态切换配置信息

    [转载:https://blog.csdn.net/blueheart20/article/details/52838093] 1. Maven中的profile设置 Maven是目前主流的项目代码结 ...

随机推荐

  1. 2-5 Flutter开发环境与Android开发环境设置详解(Windows)

    第二个是国内服务器的网址 andoid stuido的一些使用的说明文档 https://developer.android.google.cn/studio/intro 安装Flutter Dart ...

  2. ASP.NET Core会议管理平台实战_4、参数校验、操作结果封装,注册参数配置

    登陆和注册之前,需要封装 前端参数的校验,ajax的封装 参数校验,创建公共的类 ,它是一个静态类 这样在调用的时候,直接一句话就可以了,这就是封装的好处 空字符串的校验 调用方式 EF的源码里面有这 ...

  3. bootstrap下拉框式标签页

    <ul id="myTab" class="nav nav-tabs"> <li class="active"> & ...

  4. 永恒之蓝(EternalBlue)MS17-010

    附加知识: 漏洞来源与背景: 这个漏洞最初是由NSA(美国国家安全局)发现的,但是他们发现漏洞他不讲,然后遭殃了吧. 后来 有一个黑客组织叫:Shadow Brokers (影子经纪人) 入侵了NSA ...

  5. IIS 中的虚拟目录 和软连接

    在WIndows 中 可以这样设置 mklink /D  C:\bb C:\cc 这样 bb 就指向 CC了 bb 在IIS中的目录其实就是虚拟目录 .这样大的文件就不用存放在IIS中了,可以放在其他 ...

  6. web测试与手机测试的区别

    1.web是B/S,移动端是C/S 2.系统的性能: B/S的优势是异地浏览和信息采集比较灵活性,随时随地只要能使用浏览器上网即可 但是客户端只能完成浏览,查询,数据输入等简单工作,绝大部分又服务器承 ...

  7. SCUT - 157 - CC和他的GCD - 容斥原理

    https://scut.online/p/157 鉴于多年(都没几个月)搞数论的经验,这种时候枚举g肯定是对的. 那么肯定是要莫比乌斯函数作为因子,因为很显然? 但是为什么要搞个负的呢?其实是因为这 ...

  8. 伪类选择器 :nth-child(even) :nth-child(odd) :nth-of-type

    属性 描述 CSS :active 向被激活的元素添加样式. 1 :focus 向拥有键盘输入焦点的元素添加样式. 2 :hover 当鼠标悬浮在元素上方时,向元素添加样式. 1 :link 向未被访 ...

  9. Luogu P3941 入阵曲【前缀和】By cellur925

    题目传送门 题目大意:给你一个\(n\)*\(m\)的矩阵,每个位置都有一个数,求有多少不同的子矩阵使得矩阵内所有数的和是\(k\)的倍数. 数据范围给的非常友好233,期望得到的暴力分:75分.前1 ...

  10. CentOS6.7 i686上安装JDK7

    内核版本: [root@heima01 java]# uname -a Linux heima01 2.6.32-573.el6.i686 #1 SMP Thu Jul 23 12:37:35 UTC ...