assembly plugin packaging

 demo1
    |____lib
    |_____demo1.jar
    |_____*****.jar
    |_____*****.jar
    |____config
    |_____*****.properties
    |_____*****.xml
    |____log
    |_____* ****.log
    |____run.bat
    |____run.sh

    is similar to build a java project, the file structure is as follows:

    demo1
    |____src/main/java
    |____src/main/config
    |____src/main/bin
    |____src/main/resources
    | ____src/main/assemble
    |____src/test/java
    |____src/test/resources
    |____target
    |____pom.xml

    Except for the addition of the src/main/assemble directory and the build file without ant, the other contents are exactly the same: the java code is placed under src/main/java; a *.properties file is placed under src/main/resources. This resource file is packaged into In the jar, the content does not need to be changed after packaging. A standard log4j.xml is placed under src/main/config, which needs to be temporarily modified before installation and running. Executable files are placed under src/main/bin.

    The usage of assembly plugin is relatively simple, mainly including:

1. Modify the pom.xml

    settings in pom.xml as follows:
    

< build >
         < plugins >
             < plugin >
                 < artifactId > maven-assembly-plugin </ artifactId >
                 < configuration >
                     <!--  not append assembly id in release file name  -->
                     < appendAssemblyId > false </ appendAssemblyId >
                     < descriptors >
                         < descriptor > src/main/assemble/package.xml </ descriptor >
                     </ descriptors >
                 </ configuration >
                 < executions >
                     < execution >
                         < id > make-assembly </ id >
                         < phase > package </ phase >
                         < goals >
                             < goal > single </ goal >
                         </ goals >
                     </ execution >
                 </ executions >
             </ plugin >
         </ plugins >
     </ build >


    The maven-assembly-plugin of <artifactId>maven-assembly-plugin</artifactId> is the standard name of this plugin, and the default version in maven2.0.* is the

    appendAssemblyId attribute to control whether the file name of the generated packaging file contains the assembly id.     The descriptor attribute specifies the configuration file of maven-assembly-plugin. Of course, I set it to src/main/assemble/package.xml. It is allowed to use multiple ones. Of course, the function is powerful and the usage is complicated. For simple cases, one is enough.     The execution setting is to inherit maven-assembly-plugin into the standard maven packaging process, so that when running maven-package, the operation of maven-assembly-plugin will be executed, so as to realize the custom packaging we need. 2. assemble descriptor file     My src/main/assemble/package.xml content is as follows:
    







< assembly  xmlns ="http://maven.apache.org/POM/4.0.0"  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd" >
     < id > package </ id >
     < formats >
         < format > zip </ format >
     </ formats >
     < includeBaseDirectory > true </ includeBaseDirectory >
     < fileSets >
         < fileSet >
             < directory > src/main/bin </ directory >
             < outputDirectory > / </ outputDirectory >
         </ fileSet >
         < fileSet >
             < directory > src/main/config </ directory >
             < outputDirectory > config </ outputDirectory >
         </ fileSet >
     </ fileSets >
     < dependencySets >
         < dependencySet >
             < outputDirectory > lib </ outputDirectory >
             < scope > runtime </ scope >
         </ dependencySet >
     </ dependencySets >
</ assembly >


    
    The detailed syntax is not introduced, please refer to the official guide, there are very detailed instructions: Assembly Descriptor Format reference

    Briefly explain:

    1) format
    format=zip Set the final file format of the package to zip.
    Other supported formats are gz, tar ,tar.gz,tar.bz2.

    2) fileset
    

     < fileSet >
             < directory > src/main/bin </ directory >
             < outputDirectory > / </ outputDirectory >
     </ fileSet >  

  
    Package the files in the src/main/bin directory to the root directory (/).

< fileSet >
             < directory > src/main/config </ directory >
             < outputDirectory > config </ outputDirectory >
</ fileSet >


    Package the files in the src/main/config directory into config.

    3) dependencySets

     < dependencySet >
             < outputDirectory > lib </ outputDirectory >
             < scope > runtime </ scope >
     </ dependencySet >


    Package the dependencies whose scope is runtime into the lib directory.


    To sum up, maven-assembly-plugin is introduced in pom.xml, then the assemble descriptor file is set as needed, and finally Run As -> Maven package is executed in eclipse, and the ***.zip file will appear in the target directory. The format and requirements are exactly the same.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326768360&siteId=291194637