idea引用外部jar包

教程: https://blog.csdn.net/zhan107876/article/details/103934498

方法1(推荐)

  1. 新建lib目录, 并将jar包放在lib目录下.
  2. pom文件添加依赖
        <dependency>
            <groupId>xxx</groupId>
            <artifactId>xxx</artifactId>
            <version>1.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/xxx.jar</systemPath>
        </dependency>
  • ${project.basedir}表示项目/模块的根目录.
  • groupId,artifactId,version信息在maven刷新后, 展开pom.properties文件中找到(有些包可能没这个文件). 不过好像随便写也可以.
    img
#Generated by Maven
#Sat Jan 21 16:38:45 CET 2017
version=4.5.3
groupId=org.apache.httpcomponents
artifactId=httpclient
  1. pom文件添加打包时, 将外部引入的jar包打包到项目jar
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <!--代表maven打包时会将外部引入的jar包打包到项目jar-->
        <includeSystemScope>true</includeSystemScope>
    </configuration>
</plugin>
  1. maven 刷新一下. 就会自动导入.

img

idea里会展开就是加载成功

方法2

  1. 根目录下新建lib目录. 将jar包复制到该目录下.

  2. 打开project structure 面板

img

  1. 引入jar

img

  1. idea中pom文件添加以下代码. 不然打包成功, 运行时会提示找不到类
    <build>        
        <resources>
            <resource>
                <directory>lib</directory>
                <targetPath>BOOT-INF/lib/</targetPath>
                <includes>
                    <include>**/*.jar</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <targetPath>BOOT-INF/classes/</targetPath>
            </resource>
        </resources>
    </build>
posted @   陈同学  阅读(663)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
历史上的今天:
2018-04-05 rabbitmq 命令行工具 执行失败.
点击右上角即可分享
微信分享提示