Maven如何优雅的引入本地jar包

  1. 问题场景:我们项目中有时候需要引入maven中央仓库没有的jar包,但是又想让这个jar能灵活的跟随项目,nexus私服和开发者本地仓库就不能严格满足代码的异地移动,此时就需要将jar随项目代码一起放到VCS中。
  2. 解决方法:在项目目录中新建lib目录,将jar放入,然后在pom.xml中添加如下dependency节点:
<dependency>
    <groupId>org.zstack</groupId>
    <artifactId>zstack-sdk</artifactId>
    <version>3.4.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/zstak-sdk-3.4.0.jar</systemPath>
<dependency>
  1. 但很多时候scope为system的时候打包不会自动打包进去的,要添加一个参数才能打包进去的。
    如果项目打包时,第三方jar打不进去,导致classNotFounException,需要在build节点中配置jar包静态资源。
    对于spring-boot项目则需要在对应的maven打包插件中添加包含systemScope的includeSystemScope配置:
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <includeSystemScope>true</includeSystemScope>
            </configuration>
        </plugin>
    </plugins>
</build>
原文地址:https://www.cnblogs.com/JaxYoun/p/12419064.html