How to make maven place all jars common to wars inside the same EAR to EAR root?

前端 未结 4 605
梦如初夏
梦如初夏 2020-12-12 18:18

We have a solution with numerous wars. Wars are similar in the sense they all use hibernate and spring. This means that we have a number of same jars inside each war. This i

4条回答
  •  心在旅途
    2020-12-12 19:06

    As you've mentioned in a comment, it's maven's task to calculate every dependency. When you're creating an artifact, with every common dependency, then you'll also have to guess, which dependencies belong there.

    It could also be possible, that you have to deploy one war, with it's dependencies on another machine without an ear, an when you set every war dependency to provided, then you're stuck again.

    The only right way, to get skinny wars is from the examples: http://maven.apache.org/plugins/maven-war-plugin/examples/skinny-wars.html

    But, and now comes the interesting part, there is one big! shortcut (which completly takes away the mentioned pain), to tell maven, which dependencies your WARs have.

    Go inside your EAR-Module an declare a second dependency on the WAR with type pom for every WAR dependency.

    
    4.0.0
    
        com.foo
        skinny
        0.0.1-SNAPSHOT
    
    ear
    ear
    
        
            com.foo
            war
            0.0.1-SNAPSHOT
            war
        
        
            com.foo
            war
            0.0.1-SNAPSHOT
            pom
        
    
    
        
            
                org.apache.maven.plugins
                maven-ear-plugin
                2.8
                
                    true
                    lib
                    
                        
                            com.foo
                            war
                        
                    
                
            
        
    
    

    Now, every WAR will be packaged independently with it's own dependencies and the EAR will be packaged with skinny WARs and every dependency inside the lib folder

    Update:

    Keep in mind, that the ear/lib folder can't be used for every dependency jar in a strict Container like JBoss EAP 6. JSF Component libraries like tomahawk, primefaces, etc. have to reside in WEB-INF/lib folder.

    A handy way to achieve this with the above described solution is to make an exclusion for the component library in the EARs pom.xml like this:

    ...
    
        
            com.foo
            war
            0.0.1-SNAPSHOT
            war
        
        
            com.foo
            war
            0.0.1-SNAPSHOT
            pom
            
                
                    org.primefaces
                    primefaces
                
            
        
    
    ...
    

    Now every dependency of the WAR will be placed in ear/lib except the component library which will be placed in WEB-INF/lib inside the WAR

提交回复
热议问题