Maven构建简单的多模块项目
- - 编程语言 - ITeye博客一般web项目会进行分模块开发. 这里简单分为domain(领域层)、persist(持久层)、service(业务层)、web(交互控制层). 1、创建simple-parent,用来给各个子模块继承. 1)进入命令行,输入以下命令:. 可以看到在当前目录生成了simple-parent目录,里面有一个src目录和一个pom.xml文件.
mvn archetype:generate -DgroupId=cn.luxh -DartifactId=simple-parent -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent</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>
mvn archetype:generate -DgroupId=cn.luxh -DartifactId=simple-domain -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
<modules>
<module>simple-domain</module>
</modules>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent</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>
<modules>
<module>simple-domain</module>
</modules>
</project>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-domain</artifactId>
<packaging>jar</packaging>
<name>simple-domain</name>
<url>http://maven.apache.org</url>
</project>
mvn archetype:generate -DgroupId=cn.luxh -DartifactId=simple-persist -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent</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>
<modules>
<module>simple-domain</module>
<module>simple-persist</module>
</modules>
</project>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-persist</artifactId>
<packaging>jar</packaging>
<name>simple-persist</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>cn.luxh</groupId>
<artifactId>simple-domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
mvn archetype:generate -DgroupId=cn.luxh -DartifactId=simple-service -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent</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>
<modules>
<module>simple-domain</module>
<module>simple-persist</module>
<module>simple-service</module>
</modules>
</project>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-service</artifactId>
<packaging>jar</packaging>
<name>simple-service</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>cn.luxh</groupId>
<artifactId>simple-persist</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
mvn archetype:generate -DgroupId=cn.luxh -DartifactId=simple-web -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>simple-parent</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>
<modules>
<module>simple-domain</module>
<module>simple-persist</module>
<module>simple-service</module>
<module>simple-web</module>
</modules>
</project>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-web</artifactId>
<packaging>war</packaging>
<name>simple-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>cn.luxh</groupId>
<artifactId>simple-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simple-web</finalName>
</build>
</project>
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-web</artifactId>
<packaging>war</packaging>
<name>simple-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>cn.luxh</groupId>
<artifactId>simple-service</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>simple-web</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
mvn clean install
mvn jetty:run
<?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>cn.luxh</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>simple-web</artifactId>
<packaging>war</packaging>
<name>simple-web Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>cn.luxh</groupId>
<artifactId>simple-service</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_2.4_spec</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>simple-web</finalName>
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>