Building a runnable jar with Maven 2

前端 未结 5 787
猫巷女王i
猫巷女王i 2020-11-28 18:31

I\'m relatively new to the Maven mantra, but I\'m trying to build a command-line runnable jar with Maven. I\'ve setup my dependencies, but when I run mvn install

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 19:30

    The easiest way to do this would be to create an assembly using the maven-assembly-plugin and the predefined jar-with-dependencies descriptor. You'll also need to generate a manifest with a main-class entry for this uber jar. The snippet below shows how to configure the assembly plugin to do so:

    
      
        
          maven-assembly-plugin
          
            
              jar-with-dependencies
            
            
              
                fully.qualified.MainClass
              
            
          
        
      
    
    

    Then, to generate the assembly, just run:

    mvn assembly:assembly
    

    If you want to generate the assembly as part of your build, simply bind the assembly:single mojo to the package phase:

    
      
        
          maven-assembly-plugin
          
            
              jar-with-dependencies
            
            
              
                fully.qualified.MainClass
              
            
          
          
            
              package
              
                single
              
            
          
        
      
    
    

    And simply run:

    mvn package
    

提交回复
热议问题