How does Maven enter part of the jar package specified in the dependency

  • 2021-10-11 18:50:21
  • OfStack

Come straight to the point

The environment in which the project runs already has all the code dependencies of the project, so the code of the project can be submitted to the environment to run as long as its own code is entered. But the bad thing is that there is one in the project running environment jar The bag is pom Files depend on other projects' jar Bag, when this jar When the package code changes, it is necessary to change the corresponding code in the environment jar Package, so the final item jar After entering the code of this project in the package, you need to enter the latest code of other projects.

Operation process

The template is as follows:


<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>

In progress maven Adj. package After that, the project code's target In the code, you will find that in addition to typing the project code, there are also mysql Adj. pom0 Code.

Extension of knowledge points:

maven pours dependency packets into jar

Add the following configuration to the build tab of pom. xml:


<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>
                    <!--  Specify here main Method entry 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>

The above is Maven how to enter dependency specified part of jar package details, more about Maven enter dependency jar package information please pay attention to other related articles on this site!


Related articles: