软件编程
位置:首页>> 软件编程>> java编程>> Maven如何打入依赖中指定的部分jar包

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

作者:善皮之  发布时间:2023-09-22 02:50:33 

标签: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>

在进行mavenpackage之后,项目代码的target代码中会发现除了打了项目代码之外,还有mysqlconnector代码。

知识点扩展:

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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com