Maven学习笔记1

来源:百度文库 编辑:神马文学网 时间:2024/06/30 22:20:15
1,下载Maven:http://maven.apache.org/download.html2.安装配置 Windows 2000/XP
  1. Unzip the distribution archive, i.e. apache-maven-2.2.1-bin.zip to the directory you wish to install Maven 2.2.1. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-2.2.1 will be created from the archive.
  2. Add the M2_HOME environment variable by opening up the system properties (WinKey + Pause), selecting the "Advanced" tab, and the "Environment Variables" button, then adding the M2_HOME variable in the user variables with the value C:\Program Files\Apache Software Foundation\apache-maven-2.2.1. Be sure to omit any quotation marks around the path even if it contains spaces. Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.
  3. In the same dialog, add the M2 environment variable in the user variables with the value %M2_HOME%\bin.
  4. Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
  5. In the same dialog, update/create the Path environment variable in the user variables and prepend the value %M2% to add Maven available in the command line.
  6. In the same dialog, make sure that JAVA_HOME exists in your user variables or in the system variables and it is set to the location of your JDK, e.g. C:\Program Files\Java\jdk1.5.0_02 and that %JAVA_HOME%\bin is in your Path environment variable.
  7. Open a new command prompt (Winkey + R then type cmd) and run mvn --version to verify that it is correctly installed.
3.相关指令 1)创建简单项目mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 \
-DartifactId=simple \
-DpackageName=org.sonatype.mavenbook  2)构建简单项目:mvn install  3)  站点生成和报告:mvn side 
 4)为 pom.xml 添加组织,法律和开发人员信息
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">
...
simple-weather
http://www.sonatype.com


Apache 2
http://www.apache.org/licenses/LICENSE-2.0.txt
repo
A business-friendly OSS license



Sonatype
http://www.sonatype.com



jason
Jason Van Zyl
jason@maven.org
http://www.sonatype.com
Sonatype
http://www.sonatype.com

developer

-6


...
 
5)运行项目:mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main 6)浏览项目依赖:mvn dependency:resolve
    项目的整个依赖树:mvn dependency:tree 7)执行测试: mvn test    忽略测试失败:1)

[...]



org.apache.maven.plugins
maven-surefire-plugin

true




[...]
2)mvn test -Dmaven.test.failure.ignore=true
8)跳过单元测试 mvn install -Dmaven.test.skip=true  
      or

[...]



org.apache.maven.plugins
maven-surefire-plugin

true




[...]
 9)构建一个打包好的命令行应用程序 :
   1.

[...]



maven-assembly-plugin


jar-with-dependencies





[...]

2 .   mvn install assembly:assembly
 9)优化和重构POM
...

3.3.0.ga


...

org.hibernate
hibernate-annotations
${hibernate.annotations.version}



org.hibernate
hibernate-commons-annotations
${hibernate.annotations.version}

...

...

...

3.3.0.ga
1.8.0.7

...

...




org.apache.maven.plugins
maven-compiler-plugin

1.5
1.5



org.codehaus.mojo
hibernate3-maven-plugin

2.1



hbm2ddl
annotationconfiguration





hsqldb
hsqldb
${hsqldb.version}






...