简体   繁体   English

在 Maven 项目 POM 中输入<systempath>标签未包含在生成的战争文件 WEB-INF\lib 文件夹中</systempath>

[英]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 packagemvn 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.

相关问题 在WAR的WEB-INF / lib文件夹中重命名Maven依赖项 - Renaming Maven dependency in WAR's WEB-INF/lib folder Maven:在war / WEB-INF / lib中找不到本地依赖文件 - Maven: Local dependecy file not found into war/WEB-INF/lib Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? - Is it possible to have Maven “WAR” pom.xml package up my classes up in a JAR and put the JAR in the /WEB-INF/lib folder? Maven不会在WEB-INF / lib文件夹中复制spring jars - Maven does not copy spring jars in WEB-INF/lib folder 为什么在Eclipse中构建Maven项目后,“WEB-INF / lib”文件夹显示为空? - Why does “WEB-INF/lib” folder appear to be empty after a Maven project is built within Eclipse? 我的Maven项目没有将依赖项导入WEB-INF / lib文件夹 - My maven project does not import dependencies to WEB-INF/lib folder Maven:将 war/web-inf/classes 中的类作为 jar 添加到 war/web-inf/lib - Maven: Adding classes from war/web-inf/classes as a jar to war/web-inf/lib 如何将罐子从WEB-INF / lib复制到Maven战争中的另一个文件夹 - how to copy jars from WEB-INF/lib to another folder in war in maven Maven大战并将版本号放在WEB-INF / lib中的jar中 - Maven war and put the version number in the jars in WEB-INF/lib Maven,GWT,Google Eclipse插件,在依赖项项目处于战争状态时无法将jar复制到WEB-INF / lib - Maven, GWT, Google Eclipse plugin, can not copy jar to WEB-INF/lib when dependency project is war
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM