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 @ 2023-04-05 06:55  陈同学  阅读(560)  评论(0编辑  收藏  举报