一些好的文章
我的Maven之旅
http://www.blogjava.net/sitinspring/archive/2007/06/18/125006.html
http://zyl.iteye.com/blog/41754
http://juvenshun.iteye.com/blog/359256
等等
Maven repository dependencies maven 的所有的dependency都可以在上面找到
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>2.5.6</version> </dependency>
1. mvn command
mvn -B archetype:generate -DgroupId=com.demo -Dversion=1.0 -DartifactId=demo -DarchetypeArtifactId=maven-archetype-webapp /*生成web项目的基本框架 */
mvn eclipse:eclipse -Dwtpversion=1.0 /* 转换成eclipse 下的web项目 */
将项目import进eclipse中时,需要给eclipse增加一个classpath variable,步骤:Window->Preferences->Java->Build Path->Classpath Variables,点击 New 按钮添加变量。
Name: M2_REPO
Path: 点击Folder按钮选择你的maven repository目录(如我的为:D:/MavenRepos)
OK,这样项目引用的通过maven获得的jar包就能找到了,当然是在maven repository中。
2. setting.xml
修改Maven 2.x 的默认本地仓库存储路径。
Maven 2.X.可以通过修改%MAVEN_HOME%\conf\settings.xml文件来设置本地仓库存储路径,如下:
通过修改Maven全局配置文件来配置Maven的本地仓库目录:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>D:/MavenRepos/</localRepository> ......... </settings>
3. pom.xml
SCM 配置
To configure the scm support for maven you need the scm configuration in your pom.xml .
<project> ... <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>SCM Sample Project</name> <url>http://somecompany.com</url> <scm> <connection>scm:svn:http://somerepository.com/svn_repo/trunk</connection> <developerConnection>scm:svn:https://somerepository.com/svn_repo/trunk</developerConnection> <url>http://somerepository.com/view.cvs</url> </scm> ... </project>
SCM Implementation: Subversion
SCM Url
scm:svn:svn://[username[:password]@]server_name[:port]/path_to_repository scm:svn:svn+ssh://[username@]server_name[:port]/path_to_repository scm:svn:file://[hostname]/path_to_repository scm:svn:http://[username[:password]@]server_name[:port]/path_to_repository scm:svn:https://[username[:password]@]server_name[:port]/path_to_repository
Examples
scm:svn:file:///svn/root/module
scm:svn:file://localhost/path_to_repository
scm:svn:file://my_server/path_to_repository
scm:svn:http://svn.apache.org/svn/root/module
scm:svn:https://username@svn.apache.org/svn/root/module
scm:svn:https://username:password@svn.apache.org/svn/root/module
定义自己的结构
新建一个 archetype 项目 :
mvn archetype:create\
-DgroupId=cn.prof\
-DartifactId=prof-archetype\
-DarchetypeArtifactId=maven-archetype-archetype
主要的模板文件 : archetype-resources/pom.xml
修改其中内容
修改 META-INF/maven/archetype.xml 中定义了相关的 sources
安装此项目 : mvn install
执行下面的命令创建新目录的项目:
mvn archetype:create -DgroupId=com.mergere.mvnbook \
-DartifactId=proficio-example\
-DarchetypeGroupId=com.xxx.mvn\
-DarchetypeArtifactId= prof-archetype \
-DarchetypeVersion=1.0-SNAPSHOT
Goal | Description |
---|---|
scm:add | Add a file set to the project. |
scm:bootstrap | Pull the project source from the configured scm and execute the configured goals. |
scm:branch | Branch the project. |
scm:changelog | Dump changelog contents to console. It is mainly used to test maven-scm-api's changelog command. |
scm:check-local-modification | This mojo will fail the build if there is any local modifications |
scm:checkin | Commit changes to the configured scm url. |
scm:checkout | Get a fresh copy of the latest source from the configured scm url. |
scm:diff | Display the difference of the working copy with the latest copy in the configured scm url. |
scm:edit | Edit/lock a set of files. |
scm:export | Get a fresh exported copy of the latest source from the configured scm url. |
scm:help | Display help information on maven-scm-plugin. Call mvn scm:help -Ddetail=true -Dgoal=<goal-name>to display parameter details. |
scm:list | Get the list of project files. |
scm:status | Display the modification status of the files in the configured scm url. |
scm:tag | Tag the project. |
scm:unedit | Unedit/unlock a set of files. |
scm:update | Update the local working copy with the latest source from the configured scm url. |
scm:update-subprojects | Updates all projects in a multi project build. This is useful for users who have adopted the flat project structure where the aggregator project is a sibling of the sub projects rather than sitting in the parent directory. |
scm:validate | Validate scm connection string. |