<groupId>com.alibaba</groupId>
<artifactId>pampas</artifactId>
<version>3-RC1</version>
</parent>
com.alifi.*
com.taobao.security
com.taobao.util
<groupId>com.alibaba</groupId>
<artifactId>pampas</artifactId>
<version>1</version>
</parent>
1、Maven指定编译级别
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<target>1.6</target>
<source>1.6</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
自定资源文件的编码设置:
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.3</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
指定使用的单元测试框架
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <junitArtifactName>com.alibaba.external:test.junit</junitArtifactName>
- <testNGArtifactName>com.alibaba.external:test.testng</testNGArtifactName>
- <version>2.5</version>
- <excludes>
- <exclude>**/IT*.java</exclude>
- <exclude>**/*Bean.java</exclude>
- <exclude>**/TestHelper.java</exclude>
- </excludes>
- </configuration>
- </plugin>
经过验证的排除单元测试实例:<exclude>com/alibaba/external/junit/*.java</exclude>表示为排除com.alibaba.external.junit包下面的所有java文件。
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <junitArtifactName>com.alibaba.external:test.junit
- </junitArtifactName>
- <testNGArtifactName>com.alibaba.external:test.testng
- </testNGArtifactName>
- <version>2.5</version>
- <excludes>
- <exclude>com/alibaba/external/junit/*.java</exclude>
- </excludes>
- </configuration>
- </plugin>
或者
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.4.1</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <repositories>
- <repository>
- <id>args4j-repository</id>
- <url>http://download.java.net/maven/2/</url>
- </repository>
- </repositories>
父pom中自定义,子模块从此pom中继承:
- <properties>
- <cms.groupId>com.alibaba.cms</cms.groupId>
- <cms.version>1.0.0</cms.version>
- </properties>
- <groupId>${cms.groupId}</groupId>
- <version>${cms.version}</version>
【注意】我们已经通过在项目的构建配置中加入 finalName 元素来自定义这个生成的
WAR 文件的名称。根据 simple-webapp 的 finalName ,package 阶段生成的 WAR 文件
为 target/simple-webapp.war 。
2、Eclipse的编译级别
且勾上‘use default compliance settings’
3、Eclipse中出现maven的相关依赖
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
错误:读取 C:\Documents and Settings\keju.wangkj\.m2\repository\com\sun\jdmk\jmxtools\1.2.1\jmxtools
-1.2.1.jar 时出错;error in opening zip file
错误:读取 C:\Documents and Settings\keju.wangkj\.m2\repository\com\sun\jmx\jmxri\1.2.1\jmxri-1.2.1.
jar 时出错;error in opening zip file
2 错误
6、Maven打包依赖
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-5</version>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- </plugin>
7、创建resource文件
http://www.mvnrepository.com/
2.更改默认的maven2的仓库,需在pom.xml文件中添加设置(如有私服须放置在前面)
< repositories>
< repository>
< id>ibiblio< /id>
< name>Ibiblio Maven Repository< /name>
< url>http://www.ibiblio.org/maven2< /url>
< layout>default< /layout>
< /repository>
< repository>
< id>maven< /id>
< name>Slowly office site< /name>
< url>http://repo1.maven.org/maven2< /url>
< /repository>
< /repositories>
<repositories><repository> </repository></repositories>
[INFO] ------------------------------------------------------------------------
[INFO] Error configuring: org.apache.maven.plugins:maven-antrun-plugin. Reason: java.lang.NoSuchMethodError: org.apache.tools.ant.util.FileUtils.close(Ljava/io/InputStream;)V
10、Maven问题排查方式
...
<localRepository>D:\java\repository</localRepository>
...
</settings>
12、执行main函数
13、为Web项目增加WTP支持
![文字颜色 Maven问题总结 - 1_Eclipse](http://tianya23.blog.51cto.com/editor/skins/default/textcolor.gif)
Maven中无法找org.apache.maven:maven-artifact:jar:2.0.9,需要手动下载等
Missing:
----------
1) org.apache.maven:maven-artifact:jar:2.0.9
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=org.apache.maven -DartifactId=maven-artifact -Dversion=2.0.9 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=org.apache.maven -DartifactId=maven-artifact -Dversion=2.0.9 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) org.apache.maven.plugins:maven-enforcer-plugin:maven-plugin:1.0-beta-1
2) org.apache.maven:maven-artifact:jar:2.0.9
使maven2在下载依赖包的同时下载其源代码包的方法:
19、仓库依赖查询
<outputDirectory>target/site</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<configuration>
<instrumentation>
<!--<ignore>.*</ignore>
-->
<excludes>
<exclude>**/*Test.class</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
21、mvn autoconf
- 描述:autoconfig工具的封装,允许在编译时,或者编译后进行参数配置。
- 注意:如果你使用了m2eclipse,发现eclipse进程挂起,请在eclipse.ini文件里面加上-DinteractiveMode=false,这样eclipse在编译项目的时候就不会执行autoconfig了,需要执行autoconfig,请在命令行使用mvn autoconf:config
列出当前构建中活动的Profile(项目的,用户的,全局的)。
help:effective-pom
显示当前构建的实际POM,包含活动的Profile。
help:effective-settings
打印出项目的实际settings, 包括从全局的settings和用户级别settings继承的
配置。
help:describe
描述插件的属性。它不需要在项目目录下运行。但是你必须提供你想要描述插件
的 groupId 和 artifactId。
23、Maven中的依赖关系查看
24、忽略测试失败
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>