Spring Boot包不存在错误

我正在用编译项目mvn clean package,但用失败了package does not exist

详细命令:

  • target/xxxx.jar通过mvn clean package在源项目中运行来获取jar文件。
  • 通过运行安装此jar文件 mvn install:install-file -Dfile=lib/xxxx.jar -DgroupId=com.company -DartifactId=source-package-name -Dversion=1.0.0 -Dpackaging=jar
  • 向目标项目添加代码,这将在源项目中使用一些功能
  • 通过运行编译目标项目mvn clean package,但失败了package does not exist

这是源项目 pom.xml

<?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.company</groupId>

<artifactId>source-package-name</artifactId>

<version>1.0.0</version>

<packaging>jar</packaging>

<name>source-package-name</name>

<description>xxxx</description>

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.3.RELEASE</version>

<relativePath/> <!-- lookup parent from repository -->

</parent>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

</properties>

<dependencies>

</dependencies>

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<executions>

<execution>

<goals>

<goal>repackage</goal>

</goals>

</execution>

</executions>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<configuration>

<argLine>-Xmx6144m</argLine>

</configuration>

</plugin>

</plugins>

</build>

</project>

这是目标项目pom.xml

<?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.company</groupId>

<artifactId>target-package-name</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

<name>target-package-name</name>

<url>http://maven.apache.org</url>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<jdk.version>1.7</jdk.version>

<smartv-common.version>0.3.5s</smartv-common.version>

<spring.version>3.0.5.RELEASE</spring.version>

</properties>

<dependencies>

</dependencies>

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<excludes>

<!-- Exclude those since they are copied from the profile folder for

the build -->

<exclude>system.properties</exclude>

</excludes>

<filtering>false</filtering>

</resource>

</resources>

<finalName>xxxxx</finalName>

<!-- Set a compiler level -->

<extensions>

<extension>

<groupId>kr.motd.maven</groupId>

<artifactId>os-maven-plugin</artifactId>

<version>1.4.1.Final</version>

</extension>

</extensions>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<source>${jdk.version}</source>

<target>${jdk.version}</target>

<encoding>UTF-8</encoding>

</configuration>

</plugin>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-war-plugin</artifactId>

<version>2.6</version>

<configuration>

<!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html

http://stackoverflow.com/questions/12729513/how-to-overwrite-files-in-the-war-file-during-maven-build -->

<webResources>

<!-- Resources from the activated profile folder -->

<resource>

<targetPath>WEB-INF/classes/</targetPath>

<includes>

<include>system.properties</include>

</includes>

</resource>

</webResources>

</configuration>

</plugin>

</plugins>

</build>

</project>

回答:

理想情况下,您不应将Spring Boot" title="Spring Boot">Spring Boot应用程序(已重新打包的内容)用作依赖项。从文档中:

像war文件一样,Spring

Boot应用程序也不打算用作依赖项。如果您的应用程序包含要与其他项目共享的类,则建议的方法是将该代码移到单独的模块中。然后,您的应用程序和其他项目可以依赖单独的模块。

如果在您的情况下无法采用建议的解决方案,则文档将继续描述替代方案:

如果您不能按照上面的建议重新排列代码,则必须配置Spring

Boot的Maven和Gradle插件以生成一个单独的工件,该工件适合用作依赖项。可执行存档不能用作依赖项,因为可执行jar格式将BOOT-INF /

classes中的应用程序类打包。这意味着当将可执行jar用作依赖项时,找不到它们。

为了产生两个工件,一个可以用作依赖项,另一个可以执行,必须指定分类器。该分类器应用于可执行归档文件的名称,保留默认归档文件以用作依赖项。

要在Maven中配置exec的分类器,可以使用以下配置:

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<configuration>

<classifier>exec</classifier>

</configuration>

</plugin>

</plugins>

</build>

以上是 Spring Boot包不存在错误 的全部内容, 来源链接: utcz.com/qa/410031.html

回到顶部