SpringCloud maven

网友投稿 595 2022-11-28

SpringCloud maven

SpringCloud maven

目录1、spring-boot-maven-plugin2、maven-assembly-plugin3、maven-assembly-plugin打包后的可执行文件缺失lib问题

1、spring-boot-maven-plugin

springboot默认打包工具为spring-boot-maven-plugin

pom配置:

org.springframework.boot

spring-boot-maven-plugin

com.gsafety.bg.enterprise.EnterpriseApplication

ZIP

com.gsafety.bg

enterprise-controller

com.gsafety.bg

enterprise-service

com.gsafety.bg

enterprise-dao

repackage

打包后的目录结构:

BOOT-INF内包含目录:lib(enterprise-service-1.0.0.jar、enterprise-dao-1.0.0.jar、enterprise-controller-1.0.0.jar)、classes、classpath.idx

2、maven-assembly-plugin

maven-assembly-plugin 插件的主要作用是允许用户将项目输出与它的依赖项、模块、站点文档、和其他文件一起组装成一个可分发的归档文件,简单的说,就是自定义打包的工具,有自己的配置文件(Assembly描述符文件)。微服务使用这个插件的概率比较高,平时普通的项目不需要这样的实现方式。

pom配置:

maven-assembly-plugin

2.4.1

enterprise

utf-8

src/main/assembly/assembly.xml

make-assembly

package

single

assembly.xml

全部可设置节点可参考官网:http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

1.0

tar.gz

true

src/main/assembly/bin

deploy

0755

target

application-server

*.jar

src/main/resources

logs/enterprise

0755

**/*

打包后的目录结构:

查看application-server文件夹内可执行文件解压目录:

发现与spring-boot-maven-plugin打包后的目录不一致,明显缺少lib内的三个jar和其他一些文件

3、maven-assembly-plugin打包后的可执行文件缺失lib问题

修改pom文件:

org.springframework.boot

spring-boot-maven-plugin

com.gsafety.bg.enterprise.EnterpriseApplication

&lwCKRGktnt;layout>ZIP

com.gsafety.bg

enterprise-controller

com.gsafety.bg

enterprise-service

com.gsafety.bg

enterprise-dao

repackage

org.apache.maven.plugins

maven-dependency-plugin

copy-dependencies

prepare-package

copy-dependencies

../../../lib

enterprise-controller,enterprise-service,enterprise-dao

maven-assembly-plugin

2.4.1

enterprise

utf-8

src/main/assembly/assembly.xml

make-assembly

package

single

即plugins先引用spring-boot-maven-plugin 后引用maven-assembly-plugin,这样spring-boot-maven-plugin会将enterprise-service-1.0.0.jar、enterprise-dao-1.0.0.jar、enterprise-controller-1.0.0.jar三个jar打包到lib中,打包后maven-assembly-plugin就会将其打包进enterprise-1.0.tar.gz。

这样enterprise-1.0.thttp://ar.gz内就包含了启动文件(deploy)、可执行文件(application-server/enterprise-main-1.0.0.jar)、日志目录(logs/enterprise),符合目前项目部署的目录结构。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:POJ 3723 Conscription——最小生成树
下一篇:POJ 3734 Blocks——矩阵快速幂
相关文章

 发表评论

暂时没有评论,来抢沙发吧~