Getting started with Maven assembly plugin with multi-module project

后端 未结 1 1078
心在旅途
心在旅途 2021-01-23 17:06

We had a guy working with us who used the maven-assembly-plugin to package all dependencies. He has since left the company and I\'m trying to figure out how he did this. I am

1条回答
  •  一生所求
    2021-01-23 17:37

    If I read your question right, what you want to do is to add a new Maven module (called runtime) to an existing project and use the maven-assembly-plugin on this new project to package it.

    The first step is then to create the Maven module. I'm not sure if Netbeans provides a facility to do this (Eclise does), but it comes down to:

    • in the section of the parent POM, add a new for runtime.
    • create a new folder called runtime at the same directory level of the parent POM
    • create a file pom.xml inside this new folder declaring the root POM as parent POM like this:

      
          ...
          ...
          ...
      
      

    Then, you need to configure the maven-assembly-plugin to do the packaging of this new module. This is done with the help of a assembly descriptor, whose format is documented here.

    To give you something to start with, consider the following POM configuration and assembly descriptor, that will package everything that is under config, data and scripts in a zip file:

    
        maven-assembly-plugin
        2.6
        
            
                make-assembly
                package
                
                    single
                
                
                    
                        src/assemble/assembly.xml
                    
                
            
         
      
    

    with the assembly.xml:

    
      distribution
      
          zip
      
      
          
              config
              /config
          
          
              data
              /data
          
          
              scripts
              /scripts
          
        
    
    

    After running mvn clean install on the parent POM, a zip file will be created under the target directory of the module runtime. It will contain the 3 specified folders.

    0 讨论(0)
提交回复
热议问题