文章源自JAVA秀-https://www.javaxiu.com/21178.html 闪耀的瞬间 收藏 分类专栏: 版权 文章源自JAVA秀-https://www.javaxiu.com/21178.html 文章源自JAVA秀-https://www.javaxiu.com/21178.html 标题可能有点绕口,在实际开发中,有时所引用的jar架包无法在 maven 中央仓库里找到,那么j就要引用本地jar包,然而在项目开发完成后,需要打包部署时,引用的本地jar包没有打包进去部署包,就会导致项目运行失败或运行错误文章源自JAVA秀-https://www.javaxiu.com/21178.html 下面分享引用本地jar与打包本地jar,总结起来很简单,分3步:文章源自JAVA秀-https://www.javaxiu.com/21178.html 先准备好本地jar包,然后在项目的resources目录创建 lib 目录,把本地jar包放进 lib 下,我以在项目中用到 微信支付的jar包作为示例 1.在Pom.xml中引用本地jar包 文章源自JAVA秀-https://www.javaxiu.com/21178.html 创建一个WeiXinPay.java类,测试本地jar包是否可以导入在代码中了,用一个main方法测试,发现可以使用 com.github.wxpay.sdk 命令空间下的 WXPay 对象,说明引用本地jar包成功 2.此时,可以在项目中进行开发了,但是打包部署项目时, wxpay-sdk-0.0.3.jar 不会打到主项目包中,为什么呢?因为还需要在 pom.xml 里面做一些配置,配置如下: 文章源自JAVA秀-https://www.javaxiu.com/21178.html 加入上面的 plugin 配置后,在 ieda 中,打开 Maven Projects,展开Lifecycle,点击 package,对项目进行打包,可以看到 idea 左下角显示 BUILD SUCCESS , Building jar: E:\git_worker\spring-web\expend\target\expend-0.0.1-SNAPSHOT.jar,项目打包后的位置 通过 好压打开 expend-0.0.1-SNAPSHOT.jar ,看看项目的jar包里面的目录与文件结构 在expend-0.0.1-SNAPSHOT.jar\BOOT-INF\lib目录下,可以看到 wxpay-sdk-0.0.3.jar 被打包进去了,如果在 pom.xml 中不加 plugin 的配置,就不会打进去,项目启动或运行后就会报错 SpringBoot项目默认使用spring-boot-maven-plugin,要打成被其他项目引用的jar包,需要更换此插件文章源自JAVA秀-https://www.javaxiu.com/21178.html 更换maven插件文章源自JAVA秀-https://www.javaxiu.com/21178.html 下篇 RabbitMQ消息队列文章源自JAVA秀-https://www.javaxiu.com/21178.html 文章源自JAVA秀-https://www.javaxiu.com/21178.htmlSpringBoot项目开发(十):引用本地jar包与打包本地jar
文章源自JAVA秀-https://www.javaxiu.com/21178.html文章源自JAVA秀-https://www.javaxiu.com/21178.html
2018-08-08 17:24:10
14197
文章源自JAVA秀-https://www.javaxiu.com/21178.html
20
spring boot
java
SpringBoot 项目开发
文章标签:
spring boot 文章源自JAVA秀-https://www.javaxiu.com/21178.html文章源自JAVA秀-https://www.javaxiu.com/21178.html
<dependency>
<groupId>com.github.wxpay</groupId>
<artifactId>wxpay-sdk</artifactId>
<version>0.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/wxpay-sdk-0.0.3.jar</systemPath>
</dependency>
1234567文章源自JAVA秀-https://www.javaxiu.com/21178.html
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/src/main/resources/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
12345678910111213文章源自JAVA秀-https://www.javaxiu.com/21178.html
文章源自JAVA秀-https://www.javaxiu.com/21178.html
文章源自JAVA秀-https://www.javaxiu.com/21178.html
SpringBoot项目打成 jar 包被其他项目引用
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
1234<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
123456789

评论