How to assemble multimodule maven project into one WAR?

后端 未结 1 1882
深忆病人
深忆病人 2020-12-28 22:31

Similar question here.

I would like to get ONE resulting WAR to be deployed from 3 different maven modules. The war modules are absolutely non-conflicting :

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 23:19

    This just requires a little advanced use of maven jar & war plugin.

    First one that has Java classes and some WEB-INF/artifacts

    Let say this represents the main WAR. You just use maven-war-plugin's Overlays feature. The most basic way is specifying the war dependency :

        
            ${groupId}
            ${rootArtifactId}-service-impl
            ${version}
            war
            runtime
        
    

    and tell maven war plugin to merge assets of this dependency into the main war (where we are now)

    
        maven-war-plugin
        
            WEB-INF/web.xml,**/**.class
            
                
                    
                    src/main/webapp/WEB-INF
                    true
                    WEB-INF
                
            
        
    
    

    You also include a jar type dependency on the second one (it will be a JAR in WEB-INF/lib/)

        
            ${groupId}
            ${rootArtifactId}-service
            ${version}
            jar
        
    

    And you also need to specify dependency on the classes from the third WAR :

        
            ${groupId}
            ${rootArtifactId}-service-impl
            ${version}
            classes
            jar
        
    

    Notice of the classifier, it is necessary because you are specifying 2 dependencies of the same artifact... To make it work, you have to set up jar plugin in the third artifact (war type artifact), regarding the classifier and the fact that you need 2 packages from one artifacts (war & jar):

    
        org.apache.maven.plugins
        maven-jar-plugin
        
        
            
                package
                
                    jar
                
                
                
                    classes
                    
                        **/**.class
                    
                
            
        
    
    

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