大佬教程收集整理的这篇文章主要介绍了带有 <systemPath> 标记的 Maven 项目 POM 中的输入未包含在生成的战争文件 WEB-INF\lib 文件夹中,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我添加了一些带有 SystemPath
标签的 Maven 依赖项:
<dependency>
<groupID>OFRestCallbroker</groupID>
<artifactID>OFRestCallbroker</artifactID>
<scope>system</scope>
<version>1.0</version>
<systemPath>${Basedir}\src\lib\OFRestCallbroker.jar</systemPath>
</dependency>
好的,所以按照stackoverflow线程之一 Add external library .jar to Spring boot .jar internal /lib
我更新到这个
<plugins>
<plugin>
<groupID>org.springframework.boot</groupID>
<artifactID>spring-boot-maven-plugin</artifactID>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
但是当我生成 .war
文件时,这些依赖项不包含在 WEB-INF 文件夹中,并且生成了一个单独的 lib 提供的文件夹,但我仍然收到此错误 java.lang.NoClassDefFoundError。
因此,当我在 tomcat 服务器上部署这些文件时。我收到 java.lang.NoClassDefFoundError
错误。
我的 Spring Boot 版本 <version>2.2.11.RELEASE</version>
请帮忙提供正确的方法并推荐一些例子
如果你有一家公司 Nexus/Artifactory,把依赖放在那里。
否则使用 @H_451_3@mvn install:install-file 将其安装到本地存储库中。
然后你可以在不使用系统范围的情况下引用它。
,如评论中所述,System
范围已弃用。最好的方法是使用像 jFrog artifactory 这样的工件管理器或在本地存储库 {home-dir}\.m2
中安装您喜欢的依赖项。
为此,您可以使用 Maven install command:
@H_451_3@mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
假设我们有一个位于项目根目录 @H_451_3@my.jar
的src\lib\my.jar
文件
然后将其作为常规 dependency
添加到我的项目的 dependencies
中:
<dependency>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
</dependency>
但是,如果您希望以一种自动方式将位于 src/lib 中的 jar 安装到本地存储库中,可以使用 @H_451_3@maven install plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<EXECUTIONS>
<execution>
<id>install-external-non-maven-jar</id>
<phase>clean</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
<file>${Basedir}/src/lib/my.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
通过执行 @H_451_3@mvn clean 命令,my.jar 文件将被安装在本地存储库中,然后通过 @H_451_3@mvn package 或 @H_451_3@mvn install 命令执行,你的 war 文件将被创建。
最终的 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/XMLscheR_593_11845@a-instance"
xsi:scheR_593_11845@aLOCATIOn="http://maven.apache.org/POM/4.0.0 https://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.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</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.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<EXECUTIONS>
<execution>
<id>install-external-non-maven-jar</id>
<phase>clean</phase>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
<file>${Basedir}/src/lib/my.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</EXECUTIONS>
</plugin>
</plugins>
</build>
</project>
以上是大佬教程为你收集整理的带有 <systemPath> 标记的 Maven 项目 POM 中的输入未包含在生成的战争文件 WEB-INF\lib 文件夹中全部内容,希望文章能够帮你解决带有 <systemPath> 标记的 Maven 项目 POM 中的输入未包含在生成的战争文件 WEB-INF\lib 文件夹中所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。