好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Maven如何打入依赖中指定的部分jar包

开门见山

  项目运行的环境里面已经有该项目的所有代码依赖,所以项目的代码只要将自己的代码打入进去就能提交到环境中运行了。但是不好的地方就是项目运行环境里面有一个 jar 包是 pom 文件依赖其它项目的 jar 包,当这个 jar 包代码发生变更的时候,需要将环境中的该代码对应的 jar 包进行替换,所以最后得到的项目 jar 包中打入该项目的代码之后还需要打入其它项目的最新代码。

操作过程

模板如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

<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 标签中加入如下配置:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

<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包的资料请关注其它相关文章!

原文链接:https://blog.csdn.net/OldDirverHelpMe/article/details/118198643

查看更多关于Maven如何打入依赖中指定的部分jar包的详细内容...

  阅读:26次