【发布时间】:2019-03-07 05:34:57
【问题描述】:
我需要帮助。我有 2 个 spring-boot-jar 项目 maven 基础,我想将第一个导入到第二个中,如图
我在 Config Spring-Boot 中导入 Util Jar 作为打击并运行 Spring Boot 但它显示错误
<dependency>
<groupId>com.ballistic</groupId>
<artifactId>adminutil</artifactId>
<version>0.1</version>
</dependency>
[错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project config: Compilation failure: Compilation failure:
Pom.xm Util-Jar
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ballistic</groupId>
<artifactId>adminutil</artifactId>
<version>0.1</version>
<packaging>jar</packaging>
<name>adminutil</name>
<description>
Util For Admin Tool Help In All Jar's
</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Log4j2 Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!-- Needed for Async Logging with Log4j 2 -->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Pom.xm 配置文件
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.ballistic</groupId>
<artifactId>config</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>config</name>
<!--
mvn install:install-file -Dfile=C:\Users\AdMaxim\Desktop\App\adminutil\target\adminutil-0.1.jar -DgroupId=com.ballistic -DartifactId=adminutil -Dversion=0.1 -Dpackaging=jar
-->
<description>
Config Help The Configuration Of All Sub Jar
</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>com.ballistic</groupId>
<artifactId>adminutil</artifactId>
<version>0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
【问题讨论】:
-
发布两个项目的 pom.xml
-
请显示编译错误...这是您发布的消息上方的行。
-
@ArunKumar 请检查一下,错误是在 util jar 中找不到类
-
由于 jar 文件内部的结构,您不能在另一个 jar 中使用 Spring Boot jar 作为依赖项。我也非常怀疑 util 项目需要是一个单独的可运行的 Spring Boot 应用程序。所以我建议/期望那里没有
spring-boot-maven-plugin。如果你真的想让它产生 2 个资源,一个由 Spring Boot 打包,另一个是一个普通的 jar。请参阅docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/… 了解如何做到这一点。 -
@M.Deinum 您的评论对我的项目有帮助,我在导入的项目中有分类器执行,现在我可以访问类:)
标签: maven spring-boot