In Maven2, what's the simplest way to build a WAR and the EAR to contain that WAR in a single POM?

前端 未结 3 677
被撕碎了的回忆
被撕碎了的回忆 2021-02-04 13:56

Situation is pretty straightforward. I have a Java webapp that I\'m converting to be built with Maven. At present, the app is built with Ant into a single WAR file, which is the

3条回答
  •  别跟我提以往
    2021-02-04 14:27

    I know this is 5 years old now, but it was still the first answer that came up when I searched. Also, whilst "that's not the maven way" is a perfectly reasonable answer for some people, others may still prefer to use a single pom as the OP asked, and it is really not that complicated.

    First, create a standard war pom.xml to generate the war file you want to include in the ear. Leave the packaging as war.

    Then write your own application.xml (in src/main/application or wherever) using a placeholder for the war file name:

    
      
        
          ${project.build.finalName}.war
          myapp
        
      
    
    

    And include any other server-specific xml files (weblogic-application.xml etc.) in the same location.

    Next, add a resources section to replace the placeholder with the war file name:

    
      
        src/main/application
        true
        
          META-INF/*.xml
        
      
    
    

    Finally, add an ant ear task to built the ear:

    
      maven-antrun-plugin
      
        
          package
          
            run
          
          
            
              
                
                
              
            
          
        
      
    
    

    And that's it.

提交回复
热议问题