8月5日:
(经过几位的解答,目前已经可以build succes,但是不知是不是因为pom依赖中选的packing标签是pom,而不是jar,导致打包成功却并没有生成包,而packing换成jar又会导致报错,报错如下图)
初始:
请教各位精英,之前工作之余尝试自己编写一套完整springboot的多模块maven项目,但是在自己尝试打包部署时出现了问题,上网看了很多教程尝试了很多次,发现在自己这里都无法正常打包……(大部分要不直接提示"Process terminated",或者"Could not find artifact com.公司域名:TestMultipleModule(项目名):pom:1.0 in alimaven (http://maven.aliyun.com/nexus/content/repositories/central/)",实际想起到的效果大概是最后每个模块都单独成为一个jar,但是是作为一个项目,放到一个tomcat中来部署,然后该每个接口,资源正常调用
大部分时候报错是这样的,看着有点懵,报错大概理解的哪个模块没有找到父模块中引入的maven中什么内容……
项目目录大概结构是这样
然后其中父项目(主模块)依赖是这样写的(主要作用是一些常量,通用的比较重要依赖,子模块等)
<?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.cjsg</groupId>
<artifactId>TestMultipleModule</artifactId>
<version>1.0</version>
<name>TestMultipleModule</name>
<description>springboot多模块测试</description>
<packaging>pom</packaging>
<!-- properties里放的都是常量,一般放各个依赖的版本,jdk的版本等,一般放在父项目,子模块写版本时直接${}即可,避免不同子模块引入的依赖版本不同引发问题 -->
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<java.version>1.8</java.version>
<druid.version>1.1.20</druid.version>
<commons-io.version>2.2</commons-io.version>
<commons-fileupload.version>1.3.1</commons-fileupload.version>
<poi.version>3.17</poi.version>
<spring-boot.version>2.1.8.RELEASE</spring-boot.version>
<pagehelper-starter.version>1.2.12</pagehelper-starter.version>
</properties>
<dependencyManagement>
<!-- 依赖项定义 -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- SpringBoot需要的依赖配置,包括启动,控制jdbc,缓存等-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<!--阿里数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!--io常用工具类 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!--文件上传工具类 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<!-- excel工具 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<!--分页插件依赖-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-starter.version}</version>
</dependency>
<!--MyBatis支持springboot的配置依赖-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
<!-- mybatis的jar包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.1</version>
</dependency>
<!--MySQL数据库配置-->
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<!-- mysql的jdbc的jar包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<!--踩坑记录,不能在父模块引进子模块,避免循环依赖报错-->
<!-- <dependency>-->
<!-- <groupId>com.cjsg</groupId>-->
<!-- <artifactId>admin</artifactId>-->
<!-- <version>1.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.cjsg</groupId>-->
<!-- <artifactId>common</artifactId>-->
<!-- <version>1.0</version>-->
<!-- </dependency>-->
</dependencies>
<modules>
<module>admin</module>
<module>common</module>
<module>startup</module>
<module>core</module>
<module>book</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
这个是项目中大多数子模块的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>TestMultipleModule</artifactId>
<groupId>com.cjsg</groupId>
<version>1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>admin</artifactId>
<description>用于测试引入模块依赖,其中资源是否可以被调用</description>
<dependencies>
<!-- spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional> <!-- 表示依赖不会传递 -->
</dependency>
<dependency>
<groupId>com.cjsg</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
然后是启动类的pom依赖(查阅一些教程说如果用tomcat部署及启动项目好像就不需要启动类启动模块等,不知有没有用处,所以还是一块贴出来了,项目中主要是配了启动相关依赖以及要启动的模块)
<?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>TestMultipleModule</artifactId>
<groupId>com.cjsg</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>startup</artifactId>
<description>启动类模块</description>
<dependencies>
<!--spring boot可以解析yml文件,如果想解析xml等非yml配置文件,需要此依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!--springboot启动相关的依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<!--需要启动使用模块,如果想使用其中哪个模块的接口,则需要引进对应模块的依赖-->
<dependency>
<groupId>com.cjsg</groupId>
<artifactId>common</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.cjsg</groupId>
<artifactId>admin</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.cjsg</groupId>
<artifactId>core</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.cjsg</groupId>
<artifactId>book</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--指定全局唯一入口-->
<mainClass>com.cjsg.TestMultipleModuleApplication</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</project>