当前位置: 首页 > news >正文

maven导入本地jar包

方法 1:使用 systemPath 引入外部依赖
如果您希望直接引用项目中的 JAR 文件,可以使用 systemPath。
在这里插入图片描述

  1. 修改 pom.xml
    在 pom.xml 中添加以下依赖配置:

<dependency>
    <groupId>com.jdwx</groupId>
    <artifactId>sms</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/java/lib/sms-1.0.jar</systemPath>
</dependency>

方式二
手动安装到本地 Maven 仓库
将外部的 JAR 文件安装到本地 Maven 仓库中,然后像普通依赖一样引用。

安装命令:

mvn install:install-file -Dfile=path/to/external-lib-1.0.jar -DgroupId=com.example -DartifactId=external-lib -Dversion=1.0 -Dpackaging=jar

以我个人电脑为例

mvn install:install-file -Dfile=D:\devtools\maven1\maven_pro\sms-jar  -DgroupId=com.jdwx -DartifactId=sms -Dversion=1.0 -Dpackaging=jar

运行截图为
在这里插入图片描述
发现还是爆红,于是打开idea
在这里插入图片描述
配置了maven的本地仓库,于是配置

mvn install:install-file -Dfile=D:\devtools\maven1\maven_pro\sms-1.0.jar -DgroupId=com.jdwx -DartifactId=sms -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=D:\devtools\maven1\maven_pro

继续执行
在这里插入图片描述

查看本地仓库有jar包,配置成功!
3. 使用私有远程仓库
将外部的 JAR 文件上传到私有 Maven 仓库(如 Nexus 或 Artifactory),然后在 pom.xml 中配置仓库地址并引用。

配置示例:
在 pom.xml 中添加私有仓库配置:

<repositories>
    <repository>
        <id>my-repo</id>
        <url>http://my-repo-url</url>
    </repository>
</repositories>

添加依赖配置:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>external-lib</artifactId>
    <version>1.0</version>
</dependency>

4.使用 maven-dependency-plugin 复制 JAR 文件
通过 Maven 插件将外部的 JAR 文件复制到项目的 target 目录,并在构建时引用。

配置示例:
在 pom.xml 中添加插件配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
                <execution>
                    <id>copy-external-lib</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>com.example</groupId>
                                <artifactId>external-lib</artifactId>
                                <version>1.0</version>
                                <type>jar</type>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

在 pom.xml 中添加依赖配置:

**

<dependency>
    <groupId>com.example</groupId>
    <artifactId>external-lib</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.build.directory}/lib/external-lib-1.0.jar</systemPath>
</dependency>

**

http://www.dtcms.com/a/73574.html

相关文章:

  • C++抽象与类的核心概念解析
  • 粗解JQHttpServer
  • 如何优化 TCP/IP 的 NCCL 通信
  • 地图(六)利用python绘制连接地图
  • 【QT:窗口】
  • 小程序API —— 51小程序界面交互 - loading 提示框
  • 旅游类小程序界面设计
  • 基于HetEmotionNet框架的多模态情绪识别系统
  • 实战2. 利用Pytorch解决 CIFAR 数据集中的图像分类为 10 类的问题——提高精度
  • 施磊老师c++(八)
  • 唤起“栈”的回忆
  • 【数据结构】栈与队列:基础 + 竞赛高频算法实操(含代码实现)
  • Web测试
  • 神聖的綫性代數速成例題7. 逆矩陣的性質、逆矩陣的求法
  • 深度学习-yolo实战项目【分类、目标检测、实例分割】?如何创建自己的数据集?如何对数据进行标注?没有GPU怎么办呢?
  • 计算机网络基础:网络配置与管理
  • ImGui 学习笔记(五) —— 字体文件加载问题
  • Redis集群扩容实战指南:从原理到生产环境最佳实践
  • DICOM医学影像数据加密技术应用的重要性及其实现方法详解
  • 优选算法的匠心之艺:二分查找专题(二)
  • 双模型协作机制的deepseek图片识别
  • Linux错误(2)程序触发SIGBUS信号分析
  • CTF类题目复现总结-真的很杂 1
  • Spring Boot 集成 Lua 脚本:实现高效业务逻辑处理
  • 【小项目】四连杆机构的Python运动学求解和MATLAB图形仿真
  • Elasticsearch:为推理端点配置分块设置
  • 【微服务】SpringBoot整合LangChain4j 操作AI大模型实战详解
  • Qt SQL-1
  • 基于MapReduce的气候数据分析
  • [JAVASE] 反射