How to build an EAR project with EJB and WAR using Maven?

前端 未结 2 1067
温柔的废话
温柔的废话 2021-02-04 16:42

I tried to create EAR Project with EJB and WAR but I have some problem. I created the main project from the Java EE 6 EAR Archetype:


    

        
2条回答
  •  醉梦人生
    2021-02-04 16:58

    I highly suggest that you understand how multi-module builds work. The Sonatype book has a great chapter describing in great detail.

    To build an EAR with an EJB and a WAR, you actually need three modules, for the EJB, WAR and EAR. The parent POM just holds everything together and has a packaging type of POM.

    So the parent pom.xml should look like this:

    
        4.0.0
    
        org.sonatype.mavenbook.multi
        simple-parent
        pom
        1.0
        Multi Chapter Simple Parent Project
    
        
            ejb-module
            war-module
            ear-module
        
    
    

    Then, each of the child POMs would look like this:

    ejb-module/pom.xml:

    
        4.0.0
        
            org.sonatype.mavenbook.multi
            simple-parent
          1.0
        
        ejb-module
        ejb
    
    

    war-module/pom.xml

    
        4.0.0
        
            org.sonatype.mavenbook.multi
            simple-parent
            1.0
        
    
        war-module
        war
        simple-webapp Maven Webapp
        
            
                org.sonatype.mavenbook.multi
                ejb-module
                1.0
            
        
    
    

    ear-module/pom.xml:

    
        4.0.0
        
            org.sonatype.mavenbook.multi
            simple-parent
            1.0
        
    
        ear-module
        ear
        EAR module
        
            
                
                    org.apache.maven.plugins
                    maven-ear-plugin
                    2.10.1
                    
                        
                            org.sonatype.mavenbook.multi
                            ejb-module
                            ejb-module.jar
                        
                        
                            org.sonatype.mavenbook.multi
                            war-module
                            /foo
                        
                    
                
            
        
    
    

提交回复
热议问题