SpringBoot引入第三方jar包或本地jar包的处理方式


在开发过程中有时会用到maven仓库里没有的jar包或者本地的jar包,这时没办法通过pom直接引入,那么该怎么解决呢

一般有两种方法

第一种是将本地jar包安装在本地maven库
第二种是将本地jar包放入项目目录中
这篇文章主要讲第二种方式,这又分两种情况,一种是打包jar包,第二种是打包war包

1. pom文件中引入jar


    javacsv
    javacsv
    system
    1.0
    ${project.basedir}/src/main/resources/lib/javacsv.jar


这时候在项目中运行是没问题了,但是使用命令mvn clean package打包之后BOOT-INF\lib里面并没有javacsv.jar包,还需要pom文件中做如下配置:

2. 打war包

2.1 定义打包类型为war

com.xx
xx-demo
0.0.1-SNAPSHOT
war

2.2 定义war包插件


    
        
            lib
            /lib/
            
                ${project.basedir}/src/main/resources/lib/
            
        
        
            src/main/resources
            
                **/*
            
        
    
    
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                
                    
                        org.projectlombok
                        lombok
                    
                
            
        
        
        
            org.apache.maven.plugins
            maven-war-plugin
            
                
                    
                        
                        src/main/resources/lib
                        WEB-INF/lib/
                        
                            **/*.jar
                        
                    
                
            
        
        
        
        
        
        
        
        
        
        
        
        
        

        
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                true
            
        
    

3. 打jar包

3.1 定义打包类型为jar

com.xx
xx-demo
0.0.1-SNAPSHOT
jar

3.2 定义jar包插件(同上面文件一样,通用都包含进去了)


    
        
            lib
            /lib/
            
                ${project.basedir}/src/main/resources/lib/
            
        
        
            src/main/resources
            
                **/*
            
        
    
    
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                
                    
                        org.projectlombok
                        lombok
                    
                
            
        
        
        
            org.apache.maven.plugins
            maven-war-plugin
            
                
                    
                        
                        src/main/resources/lib
                        WEB-INF/lib/
                        
                            **/*.jar
                        
                    
                
            
        
        
        
        
        
        
        
        
        
        
        
        
        

        
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                true
            
        
    

4. 如果不加会出现的错误或者告警

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.new3s:zghWindPowerManage:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.commons:commons-lang3:jar -> version 3.8.1 vs 3.6 @ line 85, column 21
[WARNING] 'dependencies.dependency.systemPath' for javacsv:javacsv:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/javacsv.jar will be unresolvable by dependent projects @ line 231, column 25
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.springframework.boot:spring-boot-maven-plugin @ line 275, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 

[WARNING] 'dependencies.dependency.systemPath' for javacsv:javacsv:jar should not point at files within the project directory, ${project.basedir}/src/main/resources/lib/javacsv.jar will be unresolvable by dependent projects @ line 231, column 25
打包后不存在(BOOT-INF\lib目录下)