springboot引入外部jar包并打包jar包

引入jar包

  • 1.将jar包引入项目
    • 在resources中创建lib文件夹,将jar包复制进去


  • 2.在maven中引入jar包:
    • <dependency>
          <groupId>com</groupId><!--随便填的-->
          <artifactId>fastjson</artifactId><!--jar包名字-->
          <version>1.2.8</version><!--版本号-->
          <scope>system</scope>
          <systemPath>${project.basedir}/src/main/resources/lib/fastjson-1.2.8.jar</systemPath><!--路径-->
      </dependency>
      <!--注意:重点是systemPath这个路径必须得是你jar的路径。其他的按照套路填就行,要求不是太严格。${project.basedir}只是一个系统自己的常量,不用管它-->

此时jar包已经可以正确引用了

springboot项目打包

  • 设置maven-build
    • 在pom中设置
  •     <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <!--这里写上main方法所在类的路径-->
                    <configuration>
                        <mainClass>com.test.addjar.AddjarApplication</mainClass>
                        <includeSystemScope>true</includeSystemScope><!--外部进行打包-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal><!---->
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>






猜你喜欢

转载自www.cnblogs.com/ziyue7575/p/0b6b70c5bd196b1b92b5ca0cc695ea27.html