暫時將項目分爲如下幾層:
domain(域模型層)、dao(數據庫訪問層)、service(業務邏輯層)、web(表現層),有需要再另行添加(如common等);
目錄結構:
一、app
該層爲父層,管理其它模塊層。
1.1 創建Maven Project
1.2 選擇maven-archetype-quickstart
1.3 刪除src文件夾,修改pom.xml文件,將<packaging>jar</packaging>修改爲<packaging>pom</packaging>,pom表示它是一個被繼承的模塊
修改之後的配置文件:
- <?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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>com.bdong</groupId>
- <artifactId>app</artifactId>
- <version>0.0.1-SNAPSHOT</version>
-
- <name>app</name>
- <url>http://maven.apache.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <span style="color:#ff0000;"><strong><packaging>pom</packaging></strong></span>
-
- <modules>
- <module>app-domain</module>
- <module>app-dao</module>
- <module>app-service</module>
- <module>app-web</module>
- </modules>
- </project>
二、app-domain
2.1 創建Maven Module
2.2 選擇maven-archetype-quickstart
2.3 修改app-domain目錄中的pom.xml文件,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,groupId和version會繼承app中的groupId和version,packaging設置打包方式爲jar
修改後的配置文件:
- <?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.bdong</groupId>
- <artifactId>app</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>app-domain</artifactId>
- <strong><span style="color:#ff0000;"><packaging>jar</packaging></span></strong>
-
- <name>app-domain</name>
- <url>http://maven.apache.org</url>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </project><strong>
- </strong>
三、app-dao
3.1 創建Maven Module
3.2 選擇maven-archetype-quickstart
3.3 修改app-dao目錄中的pom.xml文件,,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,因爲groupId和version會繼承app中的groupId和version,packaging設置打包方式爲jar,同時添加對app-domain模塊的依賴
修改後的配置文件:
- <?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.bdong</groupId>
- <artifactId>app</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>app-dao</artifactId>
- <packaging>jar</packaging>
-
- <name>app-dao</name>
- <url>http://maven.apache.org</url>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencies>
- <!--依賴app-domain模塊-->
- <dependency>
- <groupId>com.bdong</groupId>
- <artifactId>app-domain</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>3.8.1</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- </project>
四、app-service
4.1 創建Maven Module
4.2 選擇maven-archetype-quickstart
4.3 修改app-service目錄中的pom.xml文件,,把<groupId>com.bdong</groupId>和<version>0.0.1-SNAPSHOT</version>去掉,加上<packaging>jar</packaging>,packaging設置打包方式爲jar,同時添加對app-dao模塊的依賴,app-service依賴app-dao和app-domain,但是隻需添加app-dao的依賴即可,因爲app-dao已經依賴了app-domain。
修改後的配置文件:
修改後的配置文件:
- <?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">