[英]Enteries in Maven Project POM with <systemPath> tag does not get included in the generated war file WEB-INF\lib folder
I have added some Maven dependencies with SystemPath
tag:我添加了一些带有
SystemPath
标签的 Maven 依赖项:
<dependency>
<groupId>OFRestCallBroker</groupId>
<artifactId>OFRestCallBroker</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\lib\OFRestCallBroker.jar</systemPath>
</dependency>
Ok, so following one of the stackoverflow thread Add external library.jar to Spring boot.jar internal /lib好的,所以按照stackoverflow线程之一添加外部库。jar到Spring boot.jar内部/lib
I updated to this我更新到这个
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
But when I generate the .war
file, these dependencies are not included in the WEB-INF folder and a separate lib-provided folder is generated but still I get this error java.lang.NoClassDefFoundError.但是当我生成
.war
文件时,这些依赖项不包含在 WEB-INF 文件夹中,并且生成了一个单独的 lib-provided 文件夹,但我仍然收到此错误 java.lang.NoClassDefFoundError。
And due to this, when I deploy these files on the Tomcat server.因此,当我在 Tomcat 服务器上部署这些文件时。 I get
java.lang.NoClassDefFoundError
error.我收到
java.lang.NoClassDefFoundError
错误。
My Spring Boot version <version>2.2.11.RELEASE</version>
我的 Spring 引导版本
<version>2.2.11.RELEASE</version>
Please help out with the correct approach and preferred some example请帮助使用正确的方法并首选一些示例
If you have a company Nexus/Artifactory, put the dependency there.如果您有公司 Nexus/Artifactory,请将依赖项放在那里。
Otherwise install it into the local repository with mvn install:install-file
.否则,使用
mvn install:install-file
将其安装到本地存储库中。
Then you can reference it without using system scope.然后您可以在不使用系统 scope 的情况下引用它。
As mentioned in comments System
scope is deprecated.如评论中所述,
System
scope 已弃用。 best approach is use an artifact manager like jFrog artifactory or install your preferred dependency in your local repository {home-dir}\.m2
.最好的方法是使用像jFrog artifactory这样的工件管理器,或者在本地存储库
{home-dir}\.m2
中安装您喜欢的依赖项。
To do this you can use Maven install command :为此,您可以使用Maven 安装命令:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
suppose we have a my.jar
file located in project root directory src\lib\my.jar
假设我们有一个
my.jar
文件位于项目根目录src\lib\my.jar
Then add it as regular dependency
to dependencies
of my project:然后将其作为常规
dependency
项添加到我的项目的dependencies
项中:
<dependency>
<groupId>a.b</groupId>
<artifactId>my</artifactId>
<version>9.0.0</version>
</dependency>
But if you want an automated way to install your jars that are located in src/lib into your local repository can utilize Maven install plugin
:但是,如果您想要一种自动方式将位于 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>
By executing mvn clean
command, my.jar file will be installed in local repository and then by mvn package
or mvn install
command execution, your war file will be created.通过执行
mvn clean
命令,my.jar 文件将安装在本地存储库中,然后通过mvn package
或mvn install
命令执行,将创建您的 war 文件。
final pom.xml:最终 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.