基础知识了解: 📁Maven高级

springboot多模块项目(微服务项目)正确打包(jar)方式_springboot多个项目打成一个jar_张子行的博客的博客-CSDN博客

坑: springboot 项目打包时提示 “程序包 xxx 不存在,找不到符号”

SpringCloud分模块开发公共模块打包_springcloud公共模块打包_浪哩个啷的博客-CSDN博客

【已解决】Maven打包报错:Could not resolve dependencies,Failed to collect dependencies_layman .的博客-CSDN博客

坑:请注释这段代码:

<plugin>  
<groupId>org.apache.maven.plugins</groupId>  
<artifactId>maven-compiler-plugin</artifactId>  
<configuration>  
<!-- 必须添加此处配置javadoc才生效,  
注:该配置和lombok冲突,存在该配置则导致lombok编译报错 -->  
<annotationProcessorPaths>  
<path>  
<groupId>com.github.therapi</groupId>  
<artifactId>therapi-runtime-javadoc-scribe</artifactId>  
<version>0.15.0</version>  
</path>  
</annotationProcessorPaths>  
</configuration>  
</plugin>

否则父项目打包时一直再找不到log

image.png

springboot 打包运行报错 错误信息 Exception in thread “main“ java_lang_NoClassDefFoundError:_org_springframework_boot_loader_launchedurlclasslo_li_914 的博客 - CSDN 博客

进入正题

重点!!!!

springboot+maven 多模块项目打包时找不到类(找不到符号)_mevan 双镜像 打包找不到类_许三多 fish 的博客 - CSDN 博客

将多余代码注释掉在打包,这个代码是我为了生成spring doc添加的,需要全部注释!!!!

<?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>HL-Novel</artifactId>  
<groupId>com.hl</groupId>  
<version>3.6.1</version>  
</parent>  
<modelVersion>4.0.0</modelVersion>  
  
<artifactId>novel-front</artifactId>  
  
<name>novel-front</name>  
<description>无疆小说 前台</description>  
  
  
<dependencies>  
<dependency>  
<groupId>com.hl</groupId>  
<artifactId>novel-common</artifactId>  
</dependency>  
  
<!--JWT(Json Web Token)登录支持-->  
<dependency>  
<groupId>io.jsonwebtoken</groupId>  
<artifactId>jjwt</artifactId>  
<version>${jjwt.version}</version>  
</dependency>  
  
<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-amqp</artifactId>  
</dependency>  
  
  
<dependency>  
<groupId>io.searchbox</groupId>  
<artifactId>jest</artifactId>  
<version>${jest.version}</version>  
</dependency>  
  
<dependency>  
<groupId>org.elasticsearch.client</groupId>  
<artifactId>elasticsearch-rest-high-level-client</artifactId>  
<version>${elasticsearch.version}</version>  
</dependency>  
  
<!--aliyunOSS-->  
<dependency>  
<groupId>com.aliyun.oss</groupId>  
<artifactId>aliyun-sdk-oss</artifactId>  
<version>${aliyun-sdk-oss.version}</version>  
</dependency>  
<dependency>  
<groupId>commons-fileupload</groupId>  
<artifactId>commons-fileupload</artifactId>  
<version>${commons-fileupload.version}</version>  
</dependency>  
  
<!--FastDfs-->  
<dependency>  
<groupId>com.github.tobato</groupId>  
<artifactId>fastdfs-client</artifactId>  
<version>${fastdfs-client.version}</version>  
</dependency>  
  
<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>  
</dependency>  
  
  
  
  
<!--引入redisson分布式锁-->  
<!-- <dependency>  
<groupId>org.redisson</groupId>  
<artifactId>redisson-spring-boot-starter</artifactId>  
<version>${redisson.version}</version>  
</dependency>-->  
  
  
<dependency>  
<groupId>com.alipay.sdk</groupId>  
<artifactId>alipay-sdk-java</artifactId>  
<version>${alipay-sdk-java.version}</version>  
</dependency>  
  
<!--引入Swagger-->  
  
<dependency>  
<groupId>org.springdoc</groupId>  
<artifactId>springdoc-openapi-javadoc</artifactId>  
<version>1.6.14</version>  
</dependency>  
  
<!-- springdoc swagger ui -->  
<dependency>  
<groupId>org.springdoc</groupId>  
<artifactId>springdoc-openapi-ui</artifactId>  
<version>1.6.14</version>  
</dependency>  
  
  
  
  
</dependencies>  
  
  
<!-- <build>-->  
<!-- <plugins>-->  
<!-- <plugin>-->  
<!-- <groupId>org.springframework.boot</groupId>-->  
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->  
<!-- </plugin>-->  
<!-- </plugins>-->  
<!-- </build>-->  
<build>  
<plugins>  
<!-- <plugin>-->  
<!-- <groupId>org.apache.maven.plugins</groupId>-->  
<!-- <artifactId>maven-compiler-plugin</artifactId>-->  
<!-- <configuration>-->  
<!-- &lt;!&ndash; 必须添加此处配置javadoc才生效,-->  
<!-- 注:该配置和lombok冲突,存在该配置则导致lombok编译报错 &ndash;&gt;--><!-- <annotationProcessorPaths>-->  
<!-- <path>-->  
<!-- <groupId>com.github.therapi</groupId>-->  
<!-- <artifactId>therapi-runtime-javadoc-scribe</artifactId>-->  
<!-- <version>0.15.0</version>-->  
<!-- </path>-->  
<!-- </annotationProcessorPaths>-->  
<!-- </configuration>-->  
<!-- </plugin>-->  
  
  
<!-- &lt;!&ndash; springdoc插件(用于在verify阶段生成openapi.json) &ndash;&gt;--><!-- <plugin>-->  
<!-- <groupId>org.springdoc</groupId>-->  
<!-- <artifactId>springdoc-openapi-maven-plugin</artifactId>-->  
<!-- <version>1.3</version>-->  
<!-- <executions>-->  
<!-- <execution>-->  
<!-- <id>integration-test</id>-->  
<!-- <goals>-->  
<!-- <goal>generate</goal>-->  
<!-- </goals>-->  
<!-- </execution>-->  
<!-- </executions>-->  
<!-- <configuration>-->  
<!-- &lt;!&ndash; The local url of your (json or yaml) - 需依赖springdoc-openapi-ui&ndash;&gt;-->  
<!-- <apiDocsUrl>·</apiDocsUrl>-->  
<!-- &lt;!&ndash; api文件名称 &ndash;&gt;--><!-- <outputFileName>openapi.json</outputFileName>-->  
<!-- &lt;!&ndash; api文件输出路径(默认${project.build.directory},即target下) &ndash;&gt;--><!-- <outputDir> ${project.build.directory}</outputDir>-->  
<!-- &lt;!&ndash; <outputDir>/home/springdoc/maven-output</outputDir> &ndash;&gt;-->  
<!-- &lt;!&ndash; 是否跳过(默认false)&ndash;&gt;-->  
<!-- <skip>false</skip>-->  
<!-- </configuration>-->  
<!-- </plugin>-->  
<!-- <plugin>-->  
<!-- <groupId>org.springframework.boot</groupId>-->  
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->  
<!-- &lt;!&ndash;springdoc-openapi-maven-plugin插件依赖以下配置 &ndash;&gt;--><!-- <configuration>-->  
<!-- <jvmArguments>-Dspring.application.admin.enabled=true</jvmArguments>-->  
<!-- </configuration>-->  
<!-- <executions>-->  
<!-- <execution>-->  
<!-- <id>pre-integration-test</id>-->  
<!-- <goals>-->  
<!-- <goal>start</goal>-->  
<!-- </goals>-->  
<!-- </execution>-->  
<!-- <execution>-->  
<!-- <id>post-integration-test</id>-->  
<!-- <goals>-->  
<!-- <goal>stop</goal>-->  
<!-- </goals>-->  
<!-- </execution>-->  
<!-- </executions>-->  
<!-- </plugin>-->  
<!-- 将相同groupId的依赖模块打包进来 -->  
<plugin>  
<groupId>org.apache.maven.plugins</groupId>  
<artifactId>maven-shade-plugin</artifactId>  
<configuration>  
<createDependencyReducedPom>false</createDependencyReducedPom>  
</configuration>  
<executions>  
<execution>  
<phase>package</phase>  
<goals>  
<goal>shade</goal>  
</goals>  
<configuration>  
<artifactSet>  
<includes>  
<include>${project.groupId}:*:*</include>  
</includes>  
</artifactSet>  
</configuration>  
</execution>  
</executions>  
</plugin>  
<plugin>  
<!--打包时去除第三方依赖-->  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-maven-plugin</artifactId>  
<configuration>  
<layout>ZIP</layout>  
<includes>  
<include>  
<groupId>non-exists</groupId>  
<artifactId>non-exists</artifactId>  
</include>  
</includes>  
  
</configuration>  
</plugin>  
<!--拷贝第三方依赖文件到指定目录-->  
<plugin>  
<groupId>org.apache.maven.plugins</groupId>  
<artifactId>maven-dependency-plugin</artifactId>  
<executions>  
<execution>  
<id>copy-dependencies</id>  
<phase>package</phase>  
<goals>  
<goal>copy-dependencies</goal>  
</goals>  
<configuration>  
<!--target/lib是依赖jar包的输出目录,根据自己喜好配置-->  
<outputDirectory>target/lib</outputDirectory>  
<excludeTransitive>false</excludeTransitive>  
<stripVersion>false</stripVersion>  
<includeScope>runtime</includeScope>  
<excludeGroupIds>${project.groupId}</excludeGroupIds>  
</configuration>  
</execution>  
</executions>  
</plugin>  
<plugin>  
<artifactId>maven-antrun-plugin</artifactId>  
<version>1.8</version>  
<executions>  
<execution>  
<phase>package</phase>  
<goals>  
<goal>run</goal>  
</goals>  
<configuration>  
<tasks>  
<!-- 文件夹 -->  
<copy todir="${project.build.directory}/build/conf" overwrite="true">  
<fileset dir="${basedir}/src/main/resources">  
<include name="**/*.*"/>  
<exclude name="mybatis/*/*.*"/>  
</fileset>  
<fileset dir="${basedir}/../novel-common/src/main/resources">  
<include name="**/*.*"/>  
<exclude name="mybatis/**"/>  
</fileset>  
</copy>  
<move todir="${project.build.directory}/build/lib">  
<fileset dir="target/lib"/>  
</move>  
<copy file="${project.build.directory}/${project.artifactId}-${project.version}.jar"  
tofile="${project.build.directory}/build/${project.artifactId}.jar" />  
  
<fixcrlf srcdir="${basedir}/src/main/build/scripts" eol="unix"/>  
<copy todir="${project.build.directory}/build/bin">  
<fileset dir="${basedir}/src/main/build/scripts">  
<include name="*.sh" />  
<include name="*.txt" />  
<include name="*.bat" />  
</fileset>  
</copy>  
<zip destfile='${project.build.directory}/build/${project.artifactId}.zip'>  
<zipfileset filemode="755" dir= '${project.build.directory}/build/' />  
</zip>  
</tasks>  
</configuration>  
</execution>  
</executions>  
</plugin>  
</plugins>  
</build>  
  
</project>
 

Novel-Front模块依赖于Novel-Commom模块,而Common模块只被依赖而不运行,所以需要先Install一下,然后Front再package,否则部署时会找不到common模块的相关类