Maven如何打入依赖中指定的部分jar包
开门见山
项目运行的环境里面已经有该项目的所有代码依赖,所以项目的代码只要将自己的代码打入进去就能提交到环境中运行了。但是不好的地方就是项目运行环境里面有一个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>
以上就是Maven如何打入依赖中指定的部分jar包的详细内容,更多关于Maven打入依赖jar包的资料请关注脚本之家其它相关文章!
相关文章
Spring Data JPA例子代码[基于Spring Boot、Mysql]
这篇文章主要介绍了Spring Data JPA例子代码[基于Spring Boot、Mysql],小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-04-04Java常用锁synchronized和ReentrantLock的区别
这篇文章主要介绍了Java常用锁synchronized和ReentrantLock的区别,二者的功效都是相同的,但又有很多不同点,下面我们就进入文章了解具体的相关内容吧。需要的小伙伴也可以参考一下2022-05-05
最新评论