maven创建多模块化项目(一)
1.cd到要生成项目位置目录
2.执行mvn archetype:generate -DgroupId=com.yyu.cms -DartifactId=appcms -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
删除src目录,修改pom.xml中的packaging为pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <name>appcms</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
3.cd到appcms目录
4.执行mvn archetype:generate -DgroupId=com.yyu.cms.common -DartifactId=appcms-common -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
5.执行mvn archetype:generate -DgroupId=com.yyu.cms.domain -DartifactId=appcms-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
6.执行mvn archetype:generate -DgroupId=com.yyu.cms.dao -DartifactId=appcms-dao -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
7.执行mvn archetype:generate -DgroupId=com.yyu.cms.service -DartifactId=appcms-service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
8.执行mvn archetype:generate -DgroupId=com.yyu.cms.web -DartifactId=appcms-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
9.得到如下目录
10.导入到IDEA
11.删除4-8生成的子模块中的<version>1.0-SNAPSHOT</version>(自动继承父version) 同时加入<packaging>jar</packaging>,添加modules之间的依赖,删除自动生成的APP.java文件
修改后的父pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <name>appcms</name> <url>http://maven.apache.org</url> <dependencyManagement> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>${junit.version}</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>appcms-common</module> <module>appcms-domain</module> <module>appcms-dao</module> <module>appcms-service</module> <module>appcms-web</module> </modules> <properties> <app.version>${project.version}</app.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <java.version>1.8</java.version> <junit.version>3.8.1</junit.version> </properties> </project>
修改后的appcms-common pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.yyu.cms.common</groupId> <artifactId>appcms-common</artifactId> <packaging>jar</packaging> <name>appcms-common</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
修改后的appcms-domain pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.yyu.cms.domain</groupId> <artifactId>appcms-domain</artifactId> <packaging>jar</packaging> <name>appcms-domain</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
修改后的appcms-dao pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.yyu.cms.dao</groupId> <artifactId>appcms-dao</artifactId> <packaging>jar</packaging> <name>appcms-dao</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.yyu.cms.common</groupId> <artifactId>appcms-common</artifactId> <version>${app.version}</version> </dependency> <dependency> <groupId>com.yyu.cms.domain</groupId> <artifactId>appcms-domain</artifactId> <version>${app.version}</version> </dependency> </dependencies> </project>
修改后的appcms-service pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.yyu.cms.service</groupId> <artifactId>appcms-service</artifactId> <packaging>jar</packaging> <name>appcms-service</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.yyu.cms.dao</groupId> <artifactId>appcms-dao</artifactId> <version>${app.version}</version> </dependency> </dependencies> </project>
修改后的appcms-web pom.xml
<?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.yyu.cms</groupId> <artifactId>appcms</artifactId> <version>1.0-SNAPSHOT</version> </parent> <groupId>com.yyu.cms.web</groupId> <artifactId>appcms-web</artifactId> <packaging>war</packaging> <name>appcms-web Maven Webapp</name> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.yyu.cms.service</groupId> <artifactId>appcms-service</artifactId> <version>${app.version}</version> </dependency> </dependencies> <build> <finalName>appcms-web</finalName> </build> </project>
备注:我的maven version