关于springboot引入第三方jar包

  • 2020 年 2 月 12 日
  • 筆記

在尝试了许多方法之后要不就是打包不成功,要不就是打成war包之后服务器tomcat启动失败。后面找到一篇文章,链接

大致方法就是将jar包编译到maven的本地库。然后跟找出的一样用dependency引入就可以。

打包命令

mvn install:install-file -Dfile=sojson-demo.jar -DgroupId=com.sojson -DartifactId=com.sojson.demo -Dversion=1.0 -Dpackaging=jar

命令详解

mvn install:install-file         //mvn 命令  -Dfile=sojson-demo.jar          //要添加的包  -DgroupId=com.sojson       //pom文件对应的groupId  -DartifactId=com.sojson.demo    //pom文件对应得artifactId  -Dversion=1.0          //添加包的版本  -Dpackaging=jar 

dependency

<dependency>      <groupId>com.sojson</groupId>      <artifactId>com.sojson.demo</artifactId>      <version>1.0</version>  </dependency>

ps: 附上一个查看maven本地包的路径的代码

mvn help:effective-settings
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">    <localRepository>/Users/****/.m2/repository</localRepository>    <pluginGroups>      <pluginGroup>org.apache.maven.plugins</pluginGroup>      <pluginGroup>org.codehaus.mojo</pluginGroup>    </pluginGroups>  </settings>

这里的localRepository就是本地maven的地址啦。