| Version 15 (modified by qinhongyuan, 14 years ago) (diff) |
|---|
Maven使用(以新游戏大厅为例)
命名:
<groupId>cn.pconline.项目组</groupId> <artifactId>项目名称</artifactId> <version>版本</vernsion>
添加依赖:
所谓依赖就是开始时候所需要的包
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.0.6.RELEASE</version> </dependency>
添加中心库: 所谓中心库就是包存放的地方或者是代理的地方
<repository> <id>gamehall</id> <name>Repository hosting the gamehall</name> <url>http://192.168.75.11:8080/nexus-webapp-1.9.2.3/content/groups/public</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>false</enabled> </snapshots> <layout>default</layout> </repository>
添加依赖包时,只需要添加你所需要的那个依赖包就可以了,这个依赖包的相关依赖可以不用加,maven默认会自动帮我们加好
添加自己依赖包时,可以上传到本地仓库,也可以上传到nexus,下面是一个例子
mvn install:install-file -Dfile=fckeditor-java-core-2.6.jar -DgroupId=fckeditor-java-core -DartifactId=fckeditor-core -Dversion=2.6 -Dpackaging=jar -DgeneratePom=true
当然nexus提供界面操作上传
公司内部需要走代理访问外部的,所以在设置的时候也要加上代理 修改setting.xml文件
<proxy>
<id>pconline</id>
<active>true</active>
<protocol>http</protocol>
<host>192.168.11.254</host>
<port>8080</port>
</proxy>
当然一些模块化的结构管理,不同开发环境的设置和插件的使用等等都可以参考Maven的官方网站 http://maven.apache.org/
pom文件
Maven基本所有工作都是对pom.xml文件来进行操作的
<repositories>
<repository>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</name>
<url>http://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
- enabled表示这两个版本是否可用,snapshots是快照版,开发过程中经常使用。releases是发布版,部署上线的时候用
- updatePolicy 提示这个仓库的依赖包是否有更新的
- checksumPolicy 校验需要
- url是远程库的地址
在游戏大厅2里面使用nexus来代理,作为公司内部使用的仓库中心。
<distributionManagement> <downloadUrl></downloadUrl> <repository></repository> <site></site> </distributionManagement>
- distributionManagement部署管理
- downloadUrl提供别人下载你项目的url
- repository项目部署的地方
- site项目文文档部署的地方(游戏大厅使用这样来部署文档的,采用ftp方式上传)
这样就很好的控制项目的部署,当然有很多种方式可以处理这样的问题,可以写一个插件处理,也可以结合hudson使用脚本处理(游戏大厅暂时使用这种方式来处理)。
<build>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
<outputDirectory>${basedir}/target/classes</outputDirectory>
<testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
...
</build>
观察这些都是输出路径,但是一般我们会按照maven的规范来做。
![(please configure the [header_logo] section in trac.ini)](http://www1.pconline.com.cn/hr/2009/global/images/logo.gif)