maven create parent-child project

1. Create an aggregation module
 
1) Create a parent module, right-click and select NEW -->project-->maven-->maven Project. Parent class pom modification: <!--Specify packaging type-->
<packaging>pom</packaging>  
 
<!--Reference subclass -->
<modules>  
    <module>../ace-api</module>  
    <module>../ace-core</module>  
    <module>../ace-entity</module>
    <module>../ace-service</module>
  </modules>
 
Note: It is necessary to delete redundant folders such as src, because the aggregation module is only a tool to help the construction of other modules , and has no substantial content in itself
 

2) Delete the src file in the parent module project (optional, mainly depends on personal needs),
 select the parent module of the project, right-click, select NEW -->project-->maven-->maven Module, click Next, Enter the name of the submodule in the interface that appears, click Next, and the Select an Archetype interface appears. At this time, select maven-Archetype-site-quickStart or maven-Archetype-webapp (used when building the web layer), and then select Finish to generate a subproject.

 Then follow the prompts to create a Maven aggregation module

 
 
 
2. Create a submodule ( Java project)
Enter the Module Name (you don't need to select Create a simple project(skip archetype seletion)), click Next, and the creation method is the same as creating an aggregate module .
Select Internal for Catalog, enter web for Filter, select maven-archetype-webapp, create a Maven Web project , and follow the same steps as above.
 
3. Modify the configuration file
 
 
Subclass pom modification:
<packaging>jar</packaging>
 
<parent>   
<groupId>cn.ace.parent</groupId>
<artifactId>ace-parent</artifactId>
<version>1.0</version>   
<relativePath>../ace-parent/pom.xml</relativePath>   
  </parent> 
 
<dependencies>
     
     <dependency>   
    <groupId>cn.ace.parent</groupId>
<artifactId>ace-parent</artifactId>
    <version>1.0</version>   
    </dependency> 
    
  
  
  </dependencies>
 
Modify the pom.xml file in the parent directory, remove <groupId> cn.ace.servie </groupId> and <version>1.0-SNAPSHOT</version> , and add <packaging>jar</packaging> , because groupId and The version will inherit the groupId and version in the system-parent, and the packaging setting packaging method is jar
 

Note the <relativePath> tag, you can omit this if the pom's hierarchy is only one level apart as in this example. maven can also find child pom.

子pom中引入<parent>标签后,就会从父pom继承<version>等属性了

 

4、除了jar包依赖,插件也可以通过这样的方式进行管理

<!-- parent -->
<build>
   <pluginManagement>
      <plugins>
          <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-source-plugin</artifactId>
               <version>2.1.1</version>
          </plugin>
      </plugins>
   </pluginManagement>
</build>

 

 

<!-- childA -->
<build>   
   <plugins>
      <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-source-plugin</artifactId>
      </plugin>
   </plugins>
</build>

 

如果子pom间存在引用关系,比如childA引用到了childB的jar包
<dependency>
   <groupId>com.module</groupId>
   <artifactId>childA</artifactId>       <!--加上childA的依赖-->
   <version>1.0.0</version>
</dependency>
 
 
5.所有maven的引用放在parent中,子类继承父类。
 
 
 
6.问题解析:
1.如果项目名报错,则,报错的父子类全选右键选择maven-update project,就ok。
 

2.错误描述:

SEVERE: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener
java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

 

问题解析:

Maven项目中所有依赖(jdk/jar/classes)关系都被其管理。所以如果确定项目中确实存在该包或文件(org.springframework.web.util.Log4jConfigListener),那必定是项目没有添加maven依赖所致。

解决方案:

 

ctrl+Enter 报错项目->Deployment Assembly->Add->Java buid path entries->Next->Maven Dependencies

Clear!

此时Servers模块中的相关项目模块下多了个字节点spring-web-3.2.3.RELEASE.jar(web.xml中配置的Log4jConfigListener类所在的包)

 

 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327100018&siteId=291194637