[英]Enteries in Maven Project POM with <systemPath> tag does not get included in the generated war file WEB-INF\lib folder
我添加了一些帶有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線程之一添加外部庫。jar到Spring boot.jar內部/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-provided 文件夾,但我仍然收到此錯誤 java.lang.NoClassDefFoundError。
因此,當我在 Tomcat 服務器上部署這些文件時。 我收到java.lang.NoClassDefFoundError
錯誤。
我的 Spring 引導版本<version>2.2.11.RELEASE</version>
請幫助使用正確的方法並首選一些示例
如果您有公司 Nexus/Artifactory,請將依賴項放在那里。
否則,使用mvn install:install-file
將其安裝到本地存儲庫中。
然后您可以在不使用系統 scope 的情況下引用它。
如評論中所述, System
scope 已棄用。 最好的方法是使用像jFrog artifactory這樣的工件管理器,或者在本地存儲庫{home-dir}\.m2
中安裝您喜歡的依賴項。
為此,您可以使用Maven 安裝命令:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
假設我們有一個my.jar
文件位於項目根目錄src\lib\my.jar
然后將其作為常規dependency
項添加到我的項目的dependencies
項中:
<dependency>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
</dependency>
但是,如果您想要一種自動方式將位於 src/lib 中的 jars 安裝到本地存儲庫中,可以使用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>
通過執行mvn clean
命令,my.jar 文件將安裝在本地存儲庫中,然后通過mvn package
或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/XMLSchema-instance"
xsi:schemaLocation="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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.