java要多思考下

成长^_^

   ::  :: 新随笔 ::  ::  :: 管理 ::
  33 随笔 :: 0 文章 :: 19 评论 :: 0 Trackbacks
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文件,配置项目依赖环境
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>
........
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     
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     
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项目

技术文章收藏站点
posted on 2011-12-26 19:01 java要多思考下 阅读(4577) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: