Springboot project third-party jar package introduction && jia package conflict resolution

1 Introduce third-party jar packages

1.1 jar placement

The third-party jar package is recommended to be placed under the src / main / webapp / WEB-INF / lib path of the springboot project. If the project does not have this path, you can create a new one; in fact, see other blogs, how to place it is possible, I It is recommended that the purpose of this placement is for packaging, so that the jar package you want to reference can be packaged directly under the web-inf lib package in the war package. According to what I have seen on other blogs, I tried it myself. If the jar The package is not under the lib package, and will not be referenced in the program (of course it can be in the idea, it will not work in the server).
Insert picture description here
Insert picture description here

1.2 pom configuration

$ {project.basedir} represents the root directory of the project
$ {project.basedir} /src/main/webapp/WEB-INF/lib/ImApi.jar points to the jar package
dependency label configuration

<!--短信服务-->
<dependency>
    <groupId>com.ImApi</groupId>
    <artifactId>ImApi</artifactId>
    <version>1.0.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/ImApi.jar</systemPath>
</dependency>
<dependency>
    <groupId>com.commons-logging-1.0.4</groupId>
    <artifactId>commons-logging-1.0.4</artifactId>
    <version>1.0.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/commons-logging-1.0.4.jar</systemPath>
</dependency>

plugins tag configuration

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <includeSystemScope>true</includeSystemScope>
            <fork>true</fork>

        </configuration>
    </plugin>
    <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
                <extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
            </compilerArguments>
        </configuration>
    </plugin>
    </plugins>

2 jar package conflict

Error information
Insert picture description here
Click ( LogFactoryImpl.java:392 ) on the line below the error information to
Insert picture description here
prompt the two versions of the method.It should be that the jar package conflict causes the class loading to be unable to determine which class to load; click the first commons-loggings1.1.3, Found to be the original dependency of the system, click on the second commons-loggings1.0.4, and found to be a dependency in the third-party jar package that I referenced.After many attempts, I found that the referenced jar package must use version 1.0.4. Version 1.0.4 can be used, so use the <exclusions> tag to exclude transitive dependencies and exclude 1.1.3. Restart the project and start successfully.

Published 6 original articles · liked 0 · visits 317

Guess you like

Origin blog.csdn.net/weixin_42542288/article/details/104482341