• 那是从何处传来的钟声呢?偶尔听到那钟声,平添一份喜悦与向往之情。

Maven引入本地jar包,解决打包时找不到本地jar包

后端 Nanait 3年前 (2020-12-08) 6541次浏览 已收录 0个评论 扫描二维码
文章目录[隐藏]

由于 缺少部分引入 jar 包,服务器运行 jar 包时,会出现异常 找不到文件

 

Constructor threw exception; nested exception is java.lang.NoClassDefFoundError:XXX

 

引入本地 jar 包的代码如下:

<dependency>
        <groupId>local-sdk</groupId>
        <artifactId>test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/src/main/resources/lib/localsdk-1.0.0.jar</systemPath>
</dependency>
其中,${project.basedir} = ${basedir},两者是完全一致的,都是 maven 的内置属性。

然后会发现,代码不报红了,说明 jar 包已经引入。
但是,在执行 maven 编译时,又会报错说找不到这两个包。

解决方案:

一、适用于 springboot
重点就 < includeSystemScope > true </ includeSystemScope>这句。

<build>
        <plugins>
                <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                                <includeSystemScope>true</includeSystemScope>
                        </configuration>
                </plugin>
        </plugins>
</build>

可跳过单元测试

<!–跳过单元测试–>
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
                <skipTests>true</skipTests>
        </configuration>
</plugin>

 到此,jar 就能成功运行


何处钟 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Maven 引入本地 jar 包,解决打包时找不到本地 jar 包
喜欢 (60)
[15211539367@163.com]
分享 (0)

您必须 登录 才能发表评论!