maven笔记
clean(清理)
default(默认)
site(站点)
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">
...
<name>simple-weather</name>
<url>http://www.sonatype.com</url>
<licenses>
<license>
<name>Apache 2</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
<comments>A business-friendly OSS license</comments>
</license>
</licenses>
<organization>
<name>Sonatype</name>
<url>http://www.sonatype.com</url>
</organization>
<developers>
<developer>
<id>jason</id>
<name>Jason Van Zyl</name>
<email>jason@maven.org</email>
<url>http://www.sonatype.com</url>
<organization>Sonatype</organization>
<organizationUrl>http://www.sonatype.com</organizationUrl>
<roles>
<role>developer</role>
</roles>
<timezone>-6</timezone>
</developer>
</developers>
...
</project>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
mvn test -Dmaven.test.failure.ignore=true
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
book.ch05 -DartifactId=simple-web -DpackageName=org.sonatype.mavenbook -Darchety
peArtifactId=maven-archetype-webapp
<finalName>simple-webapp</finalName><!--可以定义最后生成的文件名-->
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
</plugin>
</plugins>
</build>
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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Chapter 6 Simple Parent Project</name>
<modules>
<module>simple-weather</module>
<module>simple-webapp</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.sonatype.mavenbook.ch06</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>simple-webapp</artifactId><!--子模块的groupId与version无须再定义,而是从父项目中继承了-->
<packaging>war</packaging>
<name>simple-webapp Maven Webapp</name>
MAVEN : %MAVEN_HOME%\bin
(可选) MAVEN_OPTS : -Xms256m -Xmx512m //原因:maven构建时,java虚拟机默认内存可能不够
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion> //当前POM模型的版本,对于Maven2及Maven 3来说,它只能是4.0.0
<groupId>com.juvenxu.mvnbook</groupId>
<artifactId>hello-world</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven Hello World Project</name>//这个是对用户友好的项目名称
</project>
mvn install //下载包
mvn clean install //一般组合使用,将当前项目安装到本地仓库中,以供其他项目使用
mvn eclipse:eclipse //生成eclipse项目 如果项目中增加或者删除包了 需要执行该命令
mvn jetty:run //在jetty(类似于tomcat) web容器中运行项目
mvn javadoc:javadoc //生成API文档
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
tifactId=jxls-core -Dversion=1.0-RC-4-SNAPSHOT -Dpackaging=jar -Dfile=d:\jxls-co
re-1.0-RC-4-SNAPSHOT.jar -DrepositoryId=nexus-snapshots -Durl=http://128.128.0.3
0:8081/nexus/content/repositories/snapshots/
另外注意要设置.m2下的文件setting.xml
 <server> 
    <id>nexus-snapshots</id> 这里的id要和-DrepositoryId的值相等
    <username>admin</username>  
    <password>admin123</password>  
  </server>
通常情况下,使用maven增加依赖时,它只下载项目依赖包的二进制文件,要想在同时下载源代码包值需要增加一个参数:mvn eclipse:eclipse -DdownloadSources=true;
此外,也可以使用maven命令:mvn dependency:sources 下载依赖包的源代码。
Maven常用命令: 
1. 创建Maven的普通java项目: 
   mvn archetype:create 
   -DgroupId=packageName 
   -DartifactId=projectName  
2. 创建Maven的Web项目:   
    mvn archetype:create 
    -DgroupId=packageName    
    -DartifactId=webappName 
    -DarchetypeArtifactId=maven-archetype-webapp    
3. 编译源代码: mvn compile 
4. 编译测试代码:mvn test-compile    
5. 运行测试:mvn test   
6. 产生site:mvn site   
7. 打包:mvn package   
8. 在本地Repository中安装jar:mvn install 
9. 清除产生的项目:mvn clean   
10. 生成eclipse项目:mvn eclipse:eclipse  
11. 生成idea项目:mvn idea:idea  
12. 组合使用goal命令,如只打包不测试:mvn -Dtest package   
13. 编译测试的内容:mvn test-compile  
14. 只打jar包: mvn jar:jar  
15. 只测试而不编译,也不测试编译:mvn test -skipping compile -skipping test-compile 
      ( -skipping 的灵活运用,当然也可以用于其他组合命令)  
16. 清除eclipse的一些系统设置:mvn eclipse:clean 
ps:
一般使用情况是这样,首先通过cvs或svn下载代码到本机,然后执行mvn eclipse:eclipse生成ecllipse项目文件,然后导入到eclipse就行了;修改代码后执行mvn compile或mvn test检验,也可以下载eclipse的maven插件。
mvn -version/-v               显示版本信息 
mvn archetype:generate        创建mvn项目 
mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app   创建mvn项目
mvn package              生成target目录,编译、测试代码,生成测试报告,生成jar/war文件 
mvn jetty:run            运行项目于jetty上, 
mvn compile              编译 
mvn test                 编译并测试 
mvn clean                清空生成的文件 
mvn site                 生成项目相关信息的网站 
mvn -Dwtpversion=1.0 eclipse:eclipse        生成Wtp插件的Web项目 
mvn -Dwtpversion=1.0 eclipse:clean          清除Eclipse项目的配置信息(Web项目) 
mvn eclipse:eclipse                         将项目转化为Eclipse项目
在应用程序用使用多个存储库 
<repositories>    
    <repository>      
        <id>Ibiblio</id>      
        <name>Ibiblio</name>      
        <url>http://www.ibiblio.org/maven/</url>    
    </repository>    
    <repository>      
        <id>PlanetMirror</id>      
        <name>Planet Mirror</name>      
        <url>http://public.planetmirror.com/pub/maven/</url>    
    </repository>  
</repositories>
mvn deploy:deploy-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar -DrepositoryId=maven-repository-inner -Durl=ftp://xxxxxxx/opt/maven/repository/
发布第三方Jar到本地库中:
mvn install:install-file -DgroupId=com -DartifactId=client -Dversion=0.1.0 -Dpackaging=jar -Dfile=d:\client-0.1.0.jar
-DdownloadSources=true
-DdownloadJavadocs=true
mvn -e              显示详细错误 信息. 
mvn validate        验证工程是否正确,所有需要的资源是否可用。 
mvn test-compile    编译项目测试代码。 。 
mvn integration-test     在集成测试可以运行的环境中处理和发布包。 
mvn verify               运行任何检查,验证包是否有效且达到质量标准。     
mvn generate-sources     产生应用需要的任何额外的源代码,如xdoclet。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lifxue/archive/2009/10/14/4662902.aspx
常用命令: 
mvn -v 显示版本 
mvn help:describe -Dplugin=help 使用 help 插件的  describe 目标来输出 Maven Help 插件的信息。 
mvn help:describe -Dplugin=help -Dfull 使用Help 插件输出完整的带有参数的目标列 
mvn help:describe -Dplugin=compiler -Dmojo=compile -Dfull 获取单个目标的信息,设置  mojo 参数和  plugin 参数。此命令列出了Compiler 插件的compile 目标的所有信息 
mvn help:describe -Dplugin=exec -Dfull 列出所有 Maven Exec 插件可用的目标 
mvn help:effective-pom 看这个“有效的 (effective)”POM,它暴露了 Maven的默认设置
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch03 -DartifactId=simple -DpackageName=org.sonatype.mavenbook 创建Maven的普通java项目,在命令行使用Maven Archetype 插件 
mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main Exec 插件让我们能够在不往 classpath 载入适当的依赖的情况下,运行这个程序 
mvn dependency:resolve 打印出已解决依赖的列表 
mvn dependency:tree 打印整个依赖树
mvn install -X 想要查看完整的依赖踪迹,包含那些因为冲突或者其它原因而被拒绝引入的构件,打开 Maven 的调试标记运行 
mvn install -Dmaven.test.skip=true 给任何目标添加maven.test.skip 属性就能跳过测试 
mvn install assembly:assembly 构建装配Maven Assembly 插件是一个用来创建你应用程序特有分发包的插件
mvn jetty:run     调用 Jetty 插件的 Run 目标在 Jetty Servlet 容器中启动 web 应用 
mvn compile       编译你的项目 
mvn clean install 删除再编译
mvn hibernate3:hbm2ddl 使用 Hibernate3 插件构造数据库
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号