maven定义的一个重要原则

   在企业级别的项目中依赖关系比较复杂时必须处理好,各个项目的依赖的关系。

公共项目中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.unutrip.common</groupId>
 <artifactId>unutrip-common-service</artifactId>

  <!---定义生成包的类型-->
 <packaging>jar</packaging>
 <name>unutrip-common-service</name>
 <url>http://XXXXXX:8080/unutrip-common-service</url>


 <parent>
  <groupId>com.unutrip</groupId>
  <artifactId>unutrip-parent</artifactId>
  <version>1.0-SNAPSHOT</version>
 </parent>


<!-- <properties>-->
<!--  <env>develop</env>-->
<!-- </properties>-->

 <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.5-FINAL</version>
        </dependency>
  <dependency>


   <groupId>com.unusap</groupId>
   <artifactId>unusap-new-remote-no-tiger</artifactId>
   <version>1.0-SNAPSHOT</version>

   <!---定义忽略的类库-->
   <exclusions>
    <exclusion>
     <groupId>commons-lang</groupId>
     <artifactId>commons-lang</artifactId>
    </exclusion>
    <exclusion>
     <groupId>commons-collections</groupId>
     <artifactId>commons-collections</artifactId>
    </exclusion>
    <exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-web</artifactId>
    </exclusion>
    <exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-aop</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
<!---针对项目的版本变化比较快的项目最好将版本的信息定义在属性元素中,使用时 ${ 版本的名称}-->

  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-beans</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context-support</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-test</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-aop</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-orm</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-jdbc</artifactId>
   <version>${spring.version}</version>
  </dependency>

  <dependency>
   <groupId>cglib</groupId>
   <artifactId>cglib-nodep</artifactId>
   <version>2.1_3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-core</artifactId>
   <version>${struts.version}</version>
   <exclusions>
    <exclusion>
     <groupId>com.sun</groupId>
     <artifactId>tools</artifactId>
    </exclusion>
   </exclusions>
  </dependency>


  <dependency>
   <groupId>org.apache.struts</groupId>
   <artifactId>struts2-convention-plugin</artifactId>
   <version>${struts.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core</artifactId>
   <version>${spring.security.version}</version>
   <exclusions>
    <exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-support</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-cas-client</artifactId>
   <version>${spring.security.version}</version>
   <exclusions>
    <exclusion>
     <groupId>org.springframework</groupId>
     <artifactId>spring-dao</artifactId>
    </exclusion>
   </exclusions>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-core-tiger</artifactId>
   <version>${spring.security.version}</version>
  </dependency>
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>3.3.2.GA</version>
  </dependency>
  <dependency>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-simple</artifactId>
   <version>1.5.2</version>
  </dependency>
  <dependency>
   <groupId>javassist</groupId>
   <artifactId>javassist</artifactId>
   <version>3.4.GA</version>
  </dependency>


  <!--
   <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>${hibernate.version}</version>
   <exclusions>
   <exclusion>
   <groupId>javax.transaction</groupId>
   <artifactId>jta</artifactId>
   </exclusion>
   <exclusion>
   <groupId>commons-collections</groupId>
   <artifactId>commons-collections</artifactId>
   </exclusion>
   </exclusions>
   </dependency>
  -->


  <dependency>


   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-annotations</artifactId>
   <version>${hibernate.annotation.version}</version>
   <exclusions>
    <exclusion>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate</artifactId>
    </exclusion>
   </exclusions>
  </dependency>


  <dependency>


   <groupId>commons-lang</groupId>
   <artifactId>commons-lang</artifactId>
   <version>2.4</version>
  </dependency>
  <dependency>
   <groupId>commons-beanutils</groupId>
   <artifactId>commons-beanutils</artifactId>
   <version>1.8.0</version>
  </dependency>
  <dependency>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
   <version>1.3</version>
  </dependency>
  <dependency>
   <groupId>commons-collections</groupId>
   <artifactId>commons-collections</artifactId>
   <version>3.2</version>
  </dependency>
  <dependency>
   <groupId>org.directwebremoting</groupId>
   <artifactId>dwr</artifactId>
   <version>2.0.3</version>
  </dependency>
  <dependency>
   <groupId>org.apache.ant</groupId>
   <artifactId>ant</artifactId>
   <version>1.7.0</version>
   <scope>compile</scope>
  </dependency>


  <dependency>
   <groupId>org.json</groupId>
   <artifactId>json</artifactId>
   <version>20090211</version>
  </dependency>


  <dependency>
   <groupId>commons-httpclient</groupId>
   <artifactId>commons-httpclient</artifactId>
   <version>3.1</version>
  </dependency>


  <dependency>
   <groupId>net.spy</groupId>
   <artifactId>memcached</artifactId>
   <version>2.0.1</version>
  </dependency>


  <dependency>
   <groupId>net.spy</groupId>
   <artifactId>spy</artifactId>
   <version>2.4</version>
  </dependency>


  <dependency>
    <groupId>jaxen</groupId>
    <artifactId>jaxen</artifactId>
    <version>1.1.1</version>
    <exclusions>
     <exclusion>
      <groupId>dom4j</groupId>
    <artifactId>dom4j</artifactId>
     </exclusion>
     <exclusion>
      <groupId>jdom</groupId>
    <artifactId>jdom</artifactId>
     </exclusion>
     <exclusion>
      <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
     </exclusion>
     <exclusion>
      <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
     </exclusion>
     <exclusion>
      <groupId>xom</groupId>
    <artifactId>xom</artifactId>
     </exclusion>
    </exclusions>
  </dependency>


  <dependency>
    <groupId>opensymphony</groupId>
    <artifactId>quartz-all</artifactId>
    <version>1.6.3</version>
  </dependency>
  <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.3</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
   <groupId>javax.mail</groupId>
   <artifactId>mail</artifactId>
   <version>1.4</version>
  </dependency>
  <dependency>
   <groupId>com.microsoft.sqlserver</groupId>
   <artifactId>sqljdbc4</artifactId>
   <version>1.0</version>
  </dependency>
 </dependencies>

 <scm>
  <connection>
   scm:cvs:pserver:danson.liu@192.168.2.210:/usr/cvsroot:unutrip-common-service
  </connection>
  <developerConnection>
   scm:cvs:pserver:danson.liu@192.168.2.210:/usr/cvsroot:unutrip-common-service
  </developerConnection>
 </scm>
</project>

 

   (1)如果项目中依赖的jar以及一些公共的信息必须在父POM中定义,

   用于减少其他子项目的POM中定义,这样可以减少项目不同类库依赖的,造成版本的之间的差异 的原因,使 项目比较换乱。

 

  (2)将兄弟项目的版本如:hibernate-annonation和hibernate-core的版本必须一致,Spring的各类库中版本必须一致,最好将版本信息定义在属性的配置中。

 

 

查看项目中各个类库的依赖关系:

mvn   dependency:tree

 

 

maven2 下载依赖包时下载其源代码包

maven2在执行eclipse:eclipse,install等命令时,默认不下载sources包。

有两个方法可以获得所依赖包的源码包:

 

1、使用命令 mvn dependency:sources

2、增加参数 mvn eclipse:eclipse -DdownloadSources=true

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值