# simple-parent **Repository Path**: 843571091/simple-parent ## Basic Information - **Project Name**: simple-parent - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-04-01 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Maven构建多模块项目 --- ### 父模块simple-parent 1、 simple-parent/pom.xml ```xml 4.0.0 com.twx.multi simple-parent pom 1.0 Multi Chapter Simple Parent Project simple-weather simple-webapp org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 junit junit 3.8.1 test ``` 注意:父模块的packaging是```pom``` 依赖的junit会传递给子模块,所以子模块中不必再显示的依赖junit了。 2、 ``引用了接下来要创建的子模块`simple-weather`和`simple-webapp` --- ### 子模块simple-weather 1、 simple-weather/pom.xml ```xml 4.0.0 com.twx.multi simple-parent 1.0 simple-weather jar Multi Chapter Simple Weather API org.apache.maven.plugins maven-surefire-plugin true ``` 注意:子模块的`parent`是指向父模块;另外,子模块的`packaging`变成了我们熟悉的jar 2、 在此模块下新建src/main/java/com/twx/weather/WeatherService.java ```java package com.twx.weather; public class WebService{ public WebService(){} public String getWeather(){ return "fine"; } } ``` --- ### 子模块simple-webapp 1、 simple-webapp/pom.xml ```xml 4.0.0 com.twx.multi simple-parent 1.0 simple-webapp jar simple-webapp Maven Webapp com.twx.multi simple-weather 1.0 simple-webapp ``` 注意:`parent`还是simple-parent;但是注意了,`dependency`依赖了子模块simple-weather。 2、 然后创建一个com.twx.webapp.WeatherCall类调用 子模块simple-weather中的WeatherService ```java package com.twx.webapp; import com.twx.weather.WeatherService; public class WeatherCall{ public static void main(String[] args){ WeatherService service = new WeatherService(); String str = service.getWeather(); System.out.println(str); } } ``` ## 执行 在simple-parent目录下,输入`mvn clean package`,再target目录就可以看见生成好的jar包了