Maven如何打入依赖中指定的部分jar包
作者:善皮之 时间:2023-09-22 02:50:33
开门见山
项目运行的环境里面已经有该项目的所有代码依赖,所以项目的代码只要将自己的代码打入进去就能提交到环境中运行了。但是不好的地方就是项目运行环境里面有一个jar
包是pom
文件依赖其它项目的jar
包,当这个jar
包代码发生变更的时候,需要将环境中的该代码对应的jar
包进行替换,所以最后得到的项目jar
包中打入该项目的代码之后还需要打入其它项目的最新代码。
操作过程
模板如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>mysql:mysql-connector-java</include>
<!--- <incldue>groupid:artifactId</include> ----->
<!--- <incldue>groupid:artifactId</include> ----->
<!--- <incldue>groupid:artifactId</include> ----->
</includes>
</artifactSet>
</configuration>
</plugin>
</plugins>
</build>
在进行maven
的package
之后,项目代码的target
代码中会发现除了打了项目代码之外,还有mysql
的connector
代码。
知识点扩展:
maven 将依赖包打入jar中
在 pom.xml 的 build 标签中加入如下配置:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此处指定main方法入口的class -->
<mainClass>com.xxx.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
来源:https://blog.csdn.net/OldDirverHelpMe/article/details/118198643
标签:Maven,打入依赖,jar包
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中流的有关知识点详解
2022-07-21 15:38:21
linux系统 java环境变量的配置方法
2022-12-10 09:34:11
Android搜索框组件SearchView的基本使用方法
2023-01-01 15:37:51
![](https://img.aspxhome.com/file/2023/0/139100_0s.png)
java web上传文件和下载文件代码片段分享
2023-10-04 19:50:50
C#通过NPOI操作Excel的实例代码
2022-01-20 17:26:29
![](https://img.aspxhome.com/file/2023/1/119601_0s.png)
springboot项目中使用Swagger的简单示例
2023-01-14 05:18:24
![](https://img.aspxhome.com/file/2023/9/62989_0s.png)
mybatis水平分表实现动态表名的项目实例
2023-04-02 22:11:42
![](https://img.aspxhome.com/file/2023/2/59772_0s.png)
SpringBoot 创建容器的实现
2022-04-03 08:41:02
Unity的IPostprocessBuildWithReport实用案例深入解析
2022-07-29 23:30:15
C#使用foreach遍历哈希表(hashtable)的方法
2022-10-07 20:00:44
Spring Cloud Config配置文件使用对称加密的方法
2021-08-09 08:50:02
![](https://img.aspxhome.com/file/2023/2/70272_0s.png)
C#装箱和拆箱操作实例分析
2021-10-25 13:17:36
Java CharacterEncodingFilter案例详解
2022-03-21 18:22:32
![](https://img.aspxhome.com/file/2023/0/62960_0s.png)
C#使用smtp发送带附件的邮件实现方法
2022-11-03 17:53:39
C#请求http向网页发送接收数据的方法
2022-05-28 15:39:20
java实现短信通信的完整教程
2023-03-23 23:03:40
![](https://img.aspxhome.com/file/2023/9/104059_0s.jpg)
Java面试必备八股文整理
2023-11-29 12:03:50
![](https://img.aspxhome.com/file/2023/8/59068_0s.jpg)
Android 如何定制vibrator的各种震动模式M 具体方法
2023-08-13 02:09:01
java加密算法分享(rsa解密、对称加密、md5加密)
2021-08-30 16:22:08
Java SpringBoot整合SpringCloud
2022-11-11 15:07:46
![](https://img.aspxhome.com/file/2023/2/63002_0s.png)