Spring boot 项目怎么引入外部jar 包

100 阅读1分钟

安装外部 JAR 到本地 Maven 仓库

这种方法推荐用于大多数情况,因为它符合 Maven 的依赖管理机制,便于维护和部署。 安装外部 JAR 使用 Maven 命令将外部 JAR 安装到本地仓库:

  • apache-maven-3.8.8\bin mvn 命令目录地址在maven目录bin目录下
mvn install:install-file -Dfile=/path/to/your-external.jar \
                         -DgroupId=com.example \
                         -DartifactId=your-external \
                         -Dversion=1.0.0 \
                         -Dpackaging=jar

这里的参数解释如下:

  • Dfile:指定外部 JAR 文件的路径。
  • DgroupId 对应 groupId,
  • DartifactId 对应 artifactId,
  • Dversion:为这个 JAR 指定一个唯一的坐标,以便在 POM 中引用。

在 pom.xml 中添加依赖 在项目的 pom.xml 文件中添加相应的依赖项:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>your-external</artifactId>
    <version>1.0.0</version>
</dependency>

构建项目 现在你可以正常运行 mvn clean package 来构建你的项目了,Maven 将自动处理所有依赖,包括你刚刚安装的外部 JAR