maven 技巧

1、添加本地jar进入仓库命令:

mvn install:install-file -Dfile=sqljdbc4.jar -Dpackaging=jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0

2、执行java Main函数命令:

mvn exec命令可以执行项目中的main函数。
  1. 首先需要编译java工程:mvn compile
  2. 不存在参数的情况下:mvn exec:java -Dexec.mainClass="***.Main"
  3. 存在参数:mvn exec:java -Dexec.mainClass="***.Main" -Dexec.args="arg0 arg1 arg2"
  4. 指定运行时库:mvn exec:java -Dexec.mainClass="***.Main" -Dexec.classpathScope=runtime
也同样可以在maven的pom文件中指定在某个阶段执行,如(将在maven的test阶段执行):
view plain copy to clipboard print ?
  1. <build>  
  2.  <plugins>  
  3.   <plugin>  
  4.    <groupId>org.codehaus.mojo</groupId>  
  5.    <artifactId>exec-maven-plugin</artifactId>  
  6.    <version>1.1.1</version>  
  7.    <executions>  
  8.     <execution>  
  9.      <phase>test</phase>  
  10.      <goals>  
  11.       <goal>java</goal>  
  12.      </goals>  
  13.      <configuration>  
  14.       <mainClass>com.vineetmanohar.module.CodeGenerator</mainClass>  
  15.       <arguments>  
  16.        <argument>arg0</argument>  
  17.        <argument>arg1</argument>  
  18.       </arguments>  
  19.      </configuration>  
  20.     </execution>  
  21.    </executions>  
  22.   </plugin>  
  23.  </plugins>  
  24. </build>  

3、访问maven中央仓库:

http://repo1.maven.org/maven2/   已经转移到http://search.maven.org/

搜索jar包信息:http://search.maven.org/#browse

4、搜索jar包的mvn信息:

http://mvnrepository.com/

https://repository.sonatype.org/#welcome

5、测试命令:

Run a single test case (variants)
----------------------------------------------------------
mvn test -Dtests.class=org.elasticsearch.package.ClassName
mvn test "-Dtests.class=*.ClassName"
----------------------------------------------------------
Run all tests in a package and sub-packages
----------------------------------------------------
mvn test "-Dtests.class=org.elasticsearch.package.*"
----------------------------------------------------
Run any test methods that contain 'esi' (like: ...r*esi*ze...).
-------------------------------
mvn test "-Dtests.method=*esi*"
-------------------------------

6、maven web项目:

使用netbeans创建maven web项目或者使用命令:

mvn archetype:create -DgroupId=com.mycompany.webapp -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp

添加插件:

<plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>7.1.0.RC1</version>
                    <configuration>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <webAppConfig>
                            <contextPath>/mvn_web</contextPath>
                        </webAppConfig>
                    </configuration>
                </plugin>
在setting.xml添加: <pluginGroup>org.mortbay.jetty</pluginGroup>

运行命令:mvn jetty:run -Djetty.port=9999

7、mvn 拷贝依赖:

mvn dependency:copy-dependencies

8、跳过测试:

mvn install -Dmaven.test.skip=true


你可能感兴趣的:(maven 技巧)