1、按項目需求拆分模塊,配置maven項目結構
2、將項目拆分為一個java項目common,與多個web項目,建立他們之間的依賴關系
項目結構如下:
demo--|
demo-common--|
src/main/java
src/main/resource
pom-common.xml
demo-web-----|
src/main/java
src/main/resource
src/main/webapp
pom-web.xml
pom.xml
3、編寫pom文件,配置項目依賴環境
2、將項目拆分為一個java項目common,與多個web項目,建立他們之間的依賴關系
項目結構如下:
demo--|
demo-common--|
src/main/java
src/main/resource
pom-common.xml
demo-web-----|
src/main/java
src/main/resource
src/main/webapp
pom-web.xml
pom.xml
3、編寫pom文件,配置項目依賴環境
3.1、pom.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
5 <name>demo</name>
7 <artifactId>demo</artifactId>
8 <groupId>com.demo</groupId>
9 <version>1.0.0-SNAPSHOT</version>
10 <packaging>pom</packaging>
11
12 <modules>
13 <module>demo-common/trunk</module>
14 <module>demo-web/trunk</module>
15 </modules>
........
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
5 <name>demo</name>
7 <artifactId>demo</artifactId>
8 <groupId>com.demo</groupId>
9 <version>1.0.0-SNAPSHOT</version>
10 <packaging>pom</packaging>
11
12 <modules>
13 <module>demo-common/trunk</module>
14 <module>demo-web/trunk</module>
15 </modules>
........
3.2、pom-common.xml
1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
4
5 <groupId>com.demo</groupId>
6 <artifactId>demo-common</artifactId>
7 <packaging>jar</packaging>
8 <version>1.0.0-SNAPSHOT</version>
9




2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3 <modelVersion>4.0.0</modelVersion>
4
5 <groupId>com.demo</groupId>
6 <artifactId>demo-common</artifactId>
7 <packaging>jar</packaging>
8 <version>1.0.0-SNAPSHOT</version>
9





3.3、pom-web.xml
1 <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">
2 <modelVersion>4.0.0</modelVersion>
3 <artifactId>demo-web</artifactId>
4 <packaging>war</packaging>
5 <version>3.0</version>
6
7 <parent>
8 <artifactId>demo</artifactId>
9 <groupId>com.demo</groupId>
10 <version>1.0.0-SNAPSHOT</version>
11 </parent>
12
13 <properties>
14 <demo.common.version>3.0.0-SNAPSHOT</demo.common.version>
15 </properties>
16
17 <build>
31 <plugins>
32 <plugin>
33 <groupId>org.apache.maven.plugins</groupId>
34 <artifactId>maven-eclipse-plugin</artifactId>
35 <version>2.8</version>
36 <configuration>
37 <wtpversion>2.0</wtpversion>
38 <sourceExcludes>
39 <sourceExclude>**/.svn/</sourceExclude>
40 </sourceExcludes>
41 <downloadSources>true</downloadSources>
42 <outputDirectory>
43 src/main/webapp/WEB-INF/classes
44 </outputDirectory>
45 </configuration>
46 </plugin>
47 <plugin>
48 <groupId>org.apache.maven.plugins</groupId>
49 <artifactId>maven-compiler-plugin</artifactId>
50 <version>2.3.2</version>
51 <configuration>
52 <source>1.6</source>
53 <target>1.6</target>
54 <encoding>UTF-8</encoding>
55 </configuration>
56 </plugin>
57 <plugin>
58 <groupId>org.apache.maven.plugins</groupId>
59 <artifactId>maven-resources-plugin</artifactId>
60 <version>2.4</version>
61 <configuration>
62 <encoding>UTF-8</encoding>
63 </configuration>
64 </plugin>
65 <plugin>
66 <groupId>org.codehaus.mojo</groupId>
67 <artifactId>aspectj-maven-plugin</artifactId>
68 <version>1.3.1</version>
69 <dependencies>
70 <dependency>
71 <groupId>org.aspectj</groupId>
72 <artifactId>aspectjrt</artifactId>
73 <version>1.6.10</version>
74 </dependency>
75 <dependency>
76 <groupId>org.aspectj</groupId>
77 <artifactId>aspectjtools</artifactId>
78 <version>1.6.10</version>
79 </dependency>
80 </dependencies>
81 <configuration>
82 <source>1.6</source>
83 <target>1.6</target>
84 <XnoInline>true</XnoInline>
85 <showWeaveInfo>true</showWeaveInfo>
86 </configuration>
96 </plugin>
97 </plugins>
98 </build>
99
100 <dependencies>
101 <dependency>
102 <groupId>com.demo</groupId>
103 <artifactId>demo-common</artifactId>
104 <version>${demo.common.version}</version>
105 </dependency>
106






2 <modelVersion>4.0.0</modelVersion>
3 <artifactId>demo-web</artifactId>
4 <packaging>war</packaging>
5 <version>3.0</version>
6
7 <parent>
8 <artifactId>demo</artifactId>
9 <groupId>com.demo</groupId>
10 <version>1.0.0-SNAPSHOT</version>
11 </parent>
12
13 <properties>
14 <demo.common.version>3.0.0-SNAPSHOT</demo.common.version>
15 </properties>
16
17 <build>
31 <plugins>
32 <plugin>
33 <groupId>org.apache.maven.plugins</groupId>
34 <artifactId>maven-eclipse-plugin</artifactId>
35 <version>2.8</version>
36 <configuration>
37 <wtpversion>2.0</wtpversion>
38 <sourceExcludes>
39 <sourceExclude>**/.svn/</sourceExclude>
40 </sourceExcludes>
41 <downloadSources>true</downloadSources>
42 <outputDirectory>
43 src/main/webapp/WEB-INF/classes
44 </outputDirectory>
45 </configuration>
46 </plugin>
47 <plugin>
48 <groupId>org.apache.maven.plugins</groupId>
49 <artifactId>maven-compiler-plugin</artifactId>
50 <version>2.3.2</version>
51 <configuration>
52 <source>1.6</source>
53 <target>1.6</target>
54 <encoding>UTF-8</encoding>
55 </configuration>
56 </plugin>
57 <plugin>
58 <groupId>org.apache.maven.plugins</groupId>
59 <artifactId>maven-resources-plugin</artifactId>
60 <version>2.4</version>
61 <configuration>
62 <encoding>UTF-8</encoding>
63 </configuration>
64 </plugin>
65 <plugin>
66 <groupId>org.codehaus.mojo</groupId>
67 <artifactId>aspectj-maven-plugin</artifactId>
68 <version>1.3.1</version>
69 <dependencies>
70 <dependency>
71 <groupId>org.aspectj</groupId>
72 <artifactId>aspectjrt</artifactId>
73 <version>1.6.10</version>
74 </dependency>
75 <dependency>
76 <groupId>org.aspectj</groupId>
77 <artifactId>aspectjtools</artifactId>
78 <version>1.6.10</version>
79 </dependency>
80 </dependencies>
81 <configuration>
82 <source>1.6</source>
83 <target>1.6</target>
84 <XnoInline>true</XnoInline>
85 <showWeaveInfo>true</showWeaveInfo>
86 </configuration>
96 </plugin>
97 </plugins>
98 </build>
99
100 <dependencies>
101 <dependency>
102 <groupId>com.demo</groupId>
103 <artifactId>demo-common</artifactId>
104 <version>${demo.common.version}</version>
105 </dependency>
106







4、這時,在demo根目錄下執行mvn package -Dmaven.test.skip=true,執行成功表明配置有效
5、在demo根目錄下執行 mvn eclipse:eclipse 生成eclipse項目環境
6、在eclipse中使用import-->maven導入maven項目
7、這時會看到eclipse里產生三個項目,一個是demo,一個是demo-common,一個是demo-web,其中demo-web是web項目
5、在demo根目錄下執行 mvn eclipse:eclipse 生成eclipse項目環境
6、在eclipse中使用import-->maven導入maven項目
7、這時會看到eclipse里產生三個項目,一個是demo,一個是demo-common,一個是demo-web,其中demo-web是web項目
技術文章收藏站點