日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

maven 打包时缺少文件_maven父子工程---子模块相互依赖打包时所遇到的问题:依赖的程序包找不到...

發布時間:2025/3/12 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 maven 打包时缺少文件_maven父子工程---子模块相互依赖打包时所遇到的问题:依赖的程序包找不到... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景:

因為之前用到的是,基于springboot框架所搭建的maven工程,而且都是相互獨立的。現研發經理要求將所有工程進行整合和規范化,所以抽出一個parent父工程,base基礎模塊(包含一些公用的實體類和工具類等),以及其他子模塊(Module A、 Module B …)。Module A 以及Module B工程都需要依賴base工程。

問題:

在對Module A進行打包時,出現問題:Module A中所依賴的base工程的util程序包不存在。即使能打包成功,用java -jar啟動jar包也會報Class Not Found,依賴的base工程的類找不到。

解決方案:

未解決之前在base工程的pom.xml中maven插件的配置如下:

org.springframework.boot

spring-boot-maven-plugin

解決base工程的pom.xml的maven配置如下:

org.springframework.boot

spring-boot-maven-plugin

exec

原因分析:

spring-boot-maven-plugin打包出來的jar是不可依賴的

我們現在整合后的maven項目有一個parent工程,打包類型為pom,下面多個spring-boot工程作為它的module,分別為base和moduleA,moduleB。假如moduleA依賴于base。如果你在base中使用了spring-boot-maven-plugin的默認配置build,或者在parent工程中使用spring-boot-maven-plugin的默認配置build。那么在clean package的時候會發現moduleA找不到base中的類。原因就是默認打包出來的jar是不可依賴的。

解決方案:

官方告訴我們,你如果不想移代碼,好吧,我這樣來給你解決,給你打兩個jar包,一個用來直接執行,一個用來依賴。于是,你需要指定一個屬性classifier,這個屬性為可執行jar包的名字后綴。比如我設置exec,原項目名為Vehicle-business。那么會得到兩個jar:Vehicle-business.jar和Vehicle-bussiness-exec.jar

官方文檔位置:84.5 Use a Spring Boot application as a dependency

總結:回到聚合maven上,如果你在parent工程中使用了spring-boot-maven-plugin作為builder,那么你的依賴module一定要用解決方案二來設置。否則你不在parent工程中用spring-boot-maven-plugin作為builder,而在需要打包的module上使用。

一般parent工程的maven插件配置如下:

org.springframework.boot

spring-boot-maven-plugin

1.8

1.8

repackage

被依賴的maven子模塊的maven插件配置如下(其余maven子模塊就不需要配置):

org.springframework.boot

spring-boot-maven-plugin

exec

其他的坑:

1.jdk8一定要指明

不指明的話在開發工具里運行沒有一點問題,如果你沒有用到java8的特性打包也沒有問題。一旦你用到了java8的特性,而且使用spring-boot-maven-plugin作為builder,一定要指明jdk版本。不然你會收到類似不識別Lambda,請使用resource8這樣的錯誤。

parent工程pom文件:

4.0.0

org.springframework.boot

spring-boot-starter-parent

1.5.6.RELEASE

com.demo

demo-parent

pom

1.0-SNAPSHOT

demo-base

demo-sync

demo-pattern

UTF-8

UTF-8

1.8

1.5.6

org.springframework.boot

spring-boot-devtools

org.springframework.boot

spring-boot-starter-web

org.springframework.boot

spring-boot-starter-test

org.springframework.cloud

spring-cloud-starter-eureka

org.springframework.cloud

spring-cloud-starter-ribbon

org.springframework.boot

spring-boot-starter-actuator

org.springframework.boot

spring-boot-starter-freemarker

redis.clients

jedis

org.springframework.data

spring-data-redis

org.springframework.boot

spring-boot-starter-redis

1.3.7.RELEASE

org.springframework

spring-jdbc

org.springframework

spring-aspects

org.mybatis

mybatis

3.2.8

org.mybatis

mybatis-spring

1.3.2

com.alibaba

fastjson

1.2.8

com.github.pagehelper

pagehelper

3.7.5

com.github.jsqlparser

jsqlparser

0.9.1

com.github.abel533

mapper

2.3.4

mysql

mysql-connector-java

com.jolbox

bonecp-spring

0.8.0.RELEASE

org.springframework.boot

spring-boot-starter

org.springframework.boot

spring-boot-starter-logging

org.springframework.boot

spring-boot-starter-log4j2

org.apache.logging.log4j

log4j-1.2-api

2.8.2

com.lmax

disruptor

3.3.6

org.dom4j

dom4j

2.1.0

io.springfox

springfox-swagger2

2.6.1

io.springfox

springfox-swagger-ui

2.6.1

org.springframework.cloud

spring-cloud-dependencies

Camden.SR7

pom

import

org.apache.maven.plugins

maven-resources-plugin

UTF-8

org.apache.maven.plugins

maven-compiler-plugin

1.8

1.8

UTF-8

org.springframework.boot

spring-boot-maven-plugin

base工程pom文件:

demo-base

4.0.0

com.demo

demo-parent

1.0-SNAPSHOT

org.springframework.boot

spring-boot-maven-plugin

exec

sync的pom文件:

demo-sync

4.0.0

com.demo

demo-parent

1.0-SNAPSHOT

com.demo

demo-base

1.0-SNAPSHOT

總結

以上是生活随笔為你收集整理的maven 打包时缺少文件_maven父子工程---子模块相互依赖打包时所遇到的问题:依赖的程序包找不到...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。