mvn

Project Descriptor Reference.:  http://maven.apache.org/maven-model/maven.html  
Introduction to Dependency Mechanism.: http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
Introduction to Repositories.: http://maven.apache.org/guides/introduction/introduction-to-repositories.html

1.用mvn新建一个项目
mvn archetype:create -DgroupId=net.tftech.app -DartifactId=my-app
2.将项目安装到mvn本地库
mvn clean install
3.mvn主要 lifecycle phases
hese are the most common default lifecycle phases executed.


validate: validate the project is correct and all necessary information is available
compile: compile the source code of the project
test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package: take the compiled code and package it in its distributable format, such as a JAR.
integration-test: process and deploy the package if necessary into an environment where integration tests can be run
verify: run any checks to verify the package is valid and meets quality criteria
install: install the package into the local repository, for use as a dependency in other projects locally
deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

clean: cleans up artifacts created by prior builds
site: generates site documentation for this project

Phases are actually mapped to underlying goals. The specific goals executed per phase is dependant upon the packaging type of the project. For example, package executes jar:jar if the project type is a JAR, and war:war is the project type is - you guessed it - a WAR.

example:
mvn clean dependency:copy-dependencies package
mvn test-compile 编译测试代码
mvn eclipse:eclipse(mvn idea:idea)

Note that the surefire plugin (which executes the test) looks for tests contained in files with a particular naming convention.
By default the tests included are:
**/*Test.java
**/Test*.java
**/*TestCase.java
And the default excludes are:
**/Abstract*Test.java
**/Abstract*TestCase.java

scope:
compile, test, and runtime

可以设置项目的module由多个项目组成,然后具体项目中使用dependency指定依赖的项目。(mvn eclipse plugin 可以更容易的使用eclipse内的项目作为依赖)

生成WEB项目
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=co
m.mycompany.app -DartifactId=my-webapp

 

-DarchetypeArtifactId 表明要使用的原形(模板),使用原形后,会按照该原形的默认配置生成一些文件。maven archetype plugin 是根据 repository 的 archetype-catalog.xml 文件,来知道仓库中有哪些原形可以使用。

参考:http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html

 

下载依赖项目的源码:

mvn dependency:sources  或者在eclipse中maven设置:Download Artifact Sources

 

-------------本机搭建maven 仓库过程 

 

1.下载 nexus bundle 包,进入bin目录运行 nexus.bat ,启动nexus服务器。

2.访问 http://127.0.0.1:8081/nexus/ 点击 repositories. -> add -> hosted reposity

   建立一个本地仓库。 配置本地仓库目录(可以从local reposity---默认在 用户主目录/.m2 中,中拷贝所有的项目到一个新目录,例如d:\maven-repos . 然后设置本地仓库目录为该目录。 

3.记录刚配置的仓库地址 例如 http://localhost:8081/nexus/content/repositories/xxx/ ,在浏览器访问之,看是否正常。

(也尝试过配置group repository不成功,不知道为什么)

 

--------------项目中配置使用 本地仓库

在pom.xml 中配置 

 

<repositories>
	<repository>
		<id>nexus</id>
		<name>Team Nexus Repository</name>			
                <url>http://localhost:8081/nexus/content/repositories/xxx</url>
	</repository>
</repositories>

<pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<name>Team Nexus Repository</name>
			<url>http://localhost:8081/nexus/content/repositories/xxx</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
</pluginRepositories>
 

 

---------------配置 mvn deploy 发布到的服务器

可以将项目发布到本地仓库,以便让别人使用,需要在pom.xml中配置:

 

 

<distributionManagement>
		<repository>
			<id>nexus-releases</id>
			<name>Team Nexus Release Repository</name>
			<url>http://localhost:8081/nexus/content/repositories/releases</url>
		</repository>
		<snapshotRepository>
			<id>nexus-snapshots</id>
			<name>Team Nexus Snapshot Repository</name>
			<url>http://localhost:8081/nexus/content/repositories/snapshots</url>
			<uniqueVersion>false</uniqueVersion>
		</snapshotRepository>
	</distributionManagement>

 

---------------------------

付:以上2个配置,如果不想每个项目都重复这些配置,可以将他们写在setting.xml的profile里面,也可以将他们写在一个parent项目的 pom.xml里的方式,然后各个子项目的pom.xml 引用该parent即可。(推荐parent方式):

 

pom.xml:

 

<parent>
		<groupId>net.tftech</groupId>
		<artifactId>tftech-app1-parent</artifactId><!-- 这个artifact之前已部署到maven上-->
		<version>1.0</version>
</parent>

  --------------------------------

 

 

在maven目录下的conf/setting.xml 配置用户名和密码

 

 

 

<server>  
    <id>nexus-releases</id>  
    <username>x</username>  
    <password>x</password>  
  </server> 
  <server>  
    <id>nexus-snapshots</id>  
    <username>x</username>  
    <password>x</password>  
  </server>     

 

参考:http://blog.csdn.net/arvinzhuo/archive/2009/06/05/4244061.aspx 

http://hi.baidu.com/g4_gc/blog/item/4da82635c0bec0365bb5f5d3.html

你可能感兴趣的:(apache,eclipse,html,maven,idea)