---
title: "Maven初学"
author: "liusu"
date: "2009-11-10T22:19:26Z"
tags: ["Eclipse", "IDEA", "Seam", "Spring", "maven"]
slug: "maven"
draft: false
lastmod: "2009-11-22T22:38:59Z"
id: 513960
url: "https://liusu.iteye.com/blog/513960"
---

Maven start常用的命令

mvn:

Make sure maven can work now:

mvn -v

1:
```
 C:\Users\hsieh\projects\javaworkspace\studyjee>mvn archetype:create -DgroupId=
com.seam -DartifactId=studyjee 
```


Create a simple java project demo within Maven

2: Generate types of archetype project

```
C:\Users\hsieh\projects\javaworkspace\studyjee>mvn archetype:generate -DgroupId=
com.seam -DartifactId=studyjee
```


Then select which type of project demo you want to crreated. Option 7 is project with Spring/Spring MVC

3:Test-compile
Run 'test' goal with 'compile' explicitly
However, remember that it isn’t necessary to run this every time; mvn test will always run the compile and test-

compile phases first, as well as all the others defined before it.

4:IDE intergration 

1>
```
idea mvn idea:idea
```

2>eclipse mvn eclipse:eclipse
Convert maven project to idea/eclipse project. With Maven intergration plugin then you can control projects in IDEs.

Maven的坐标概念理解很关键，

Maven 坐标

Maven 坐标是一组可以惟一标识工件的三元组值。坐标包含了下列三条信息：

    * 组 ID：代表制造该工件的实体或组织。例如，com.ibm.devworks 就是一个组 ID。

    * 工件 ID：实际的工件的名称。例如，主体类名为 OpsImp 的项目也许会用 OpsImp 作为其工件 ID。

    * 版本：该工件的版本号。支持的格式为 mmm.nnn.bbb-qqqqqqq-dd ，其中， mmm 是主版本号， nnn 是次版本号， bbb 代表其 bug 修复水平。 qqqqq （限定词）或 dd （构建号）也能添加到版本号中，这两项是可选项。

对 Maven 坐标的使用贯穿于 Maven 配置文件和 POM 文件中

----------Tips-------------

1：创建一个maven项目。查看maven项目的pom.xml，极其简单的。
2：Maven遵循 “惯例优先配置”的原则，所以在你看到的pom.xml里面其实少了很多东西的。通过mvn help:effective-pom命令看看吧。 可以看到实际的完整的起作用的pom.xml.
包括src放在哪里，output放在哪里，还有默认有哪些maven的plugin在起作用等等。(help是maven的一个插件，详细用法：mvn help:describe -Dplugin=help)
3：注意，effective-pom是都动态变化的。当你执行一个新的goal的时候，这个文件会被动态修改。
比如先执行 mvn dependency:tree, 谈后再执行mvn help:effective-pom对比对比。

4:部署web程序的时候，有的时候我们会在IDE里面改变一些jsp页面（js文件）等，为了让修改生效，我们需要把这些文件copy到部署目录下（web server处于热部署状态），一直手copy蛮麻烦的。 可以试试这个
mvn resources:resources 这个会将资源文件copy到该有的地方。。。


详情见：https://www6.software.ibm.com/developerworks/cn/education/java/j-mavenv2/section4.html