Run a multi-module Maven project

后端 未结 1 1127
走了就别回头了
走了就别回头了 2021-01-16 10:22

This is a basic question, I\'m just not really familiar with maven multi-module structures. Say, I have a web application. And I want to connect some modules to it (some ser

1条回答
  •  臣服心动
    2021-01-16 10:42

    If you have a multi-module project you need a structure like the following which will also be represented by the folder structure as well.

    +-- root (pom.xml)
         +--- module-1
         +--- module-2
         +--- module-war 
    

    Whereas the root module contains a thing like this:

    
    
      com.test.project
      parent
      1.0-SNAPSHOT
    
      
        module-1
        module-2
        module-war
      
    
    
    

    In the module-1 your pom should look like this:

    
      
        com.test.project
        parent
        1.0-SNAPSHOT
      
    
      module-1
    
      dependencies for the module
    
    
    

    in module-2 it look more or less the same..and in the war module it looks like:

    
      
        com.test.project
        parent
        1.0-SNAPSHOT
      
    
      war
      module-war
    
      dependencies for the module
    
    
    

    If you have dependencies between the modules for example module-1 depends on module-2 it looks like the following in module-1:

    
      
        com.test.project
        parent
        1.0-SNAPSHOT
      
    
      module-1
    
      
        
          ${project.groupId}
          module-2
          {project.version}
        
    
        ..other dependencies..
    
      
    
    
    

    To build and package your project you will go to parent folder and do simply a

    mvn clean package
    

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