zoukankan      html  css  js  c++  java
  • maven常用命令

    一、maven常用命令:

    1.mvn clean    清空产生的项目( target里)

    2.mvn compile 编译源代码

    3.mvn install    在本地repository中安装jar(包含mvn compile,mvn package,然后上传到本地仓库)

    4.mvn deploy   上传到私服(包含mvn install,然后,上传到私服)

    5.mvn package     打包

    6.mvn test           运行测试

    7.mvn site     产生site

    8.mvn test-compile   编译测试代码

    9.mvn -Dtest package  只打包不测试

    10.mvn  jar:jar    只打jar包

    11.mvn  test -skipping compile -skipping test-compile  只测试而不编译,也不测试编译

    12.mvn  deploy   

    13.mvn  source.jar   源码打包

    二、把pom文件中配置的依赖jar包打进来,打成一个包:要用maven-assembly-plugin 这个插件,在pom文件加如下配置

     1 <build>
     2         <plugins>
     3             <plugin>
     4                 <artifactId>maven-compiler-plugin</artifactId>
     5                 <version>2.3.2</version>
     6                 <configuration>
     7                     <source>1.7</source>
     8                     <target>1.7</target>
     9                 </configuration>
    10             </plugin>
    11             <plugin>
    12                 <artifactId>maven-assembly-plugin</artifactId>
    13                 <configuration>
    14                     <appendAssemblyId>false</appendAssemblyId>
    15                     <descriptorRefs>
    16                         <descriptorRef>jar-with-dependencies</descriptorRef>
    17                     </descriptorRefs>
    18                </configuration>
    19                 <executions>
    20                     <execution>
    21                         <id>make-assembly</id>
    22                         <phase>package</phase>
    23                         <goals>
    24                             <goal>assembly</goal>
    25                         </goals>
    26                     </execution>
    27                 </executions>
    28             </plugin>
    29         </plugins>
    30     </build>

    二、而下面这种配置:在eclipse中,Run as ->Maven build-> install  生成的包,只有该项目自己,<dependencies>里引入的第三方jar并没打进去;

    但用package命令,生成项目本身一个jar,还生成一个*-jar-with-dependencies.jar,依赖的jar 都在这个*-jar-with-dependencies.jar包里,项目本身的包还是它自己

     1 <build>  
     2             <plugins>  
     3                 <plugin>
     4                     <artifactId>maven-compiler-plugin</artifactId>
     5                     <version>2.3.2</version>
     6                     <configuration>
     7                         <source>1.7</source>
     8                         <target>1.7</target>
     9                     </configuration>
    10                 </plugin>
    11                 <plugin>  
    12                     <artifactId>maven-assembly-plugin</artifactId>  
    13                     <configuration>  
    14                         <descriptorRefs>  
    15                             <descriptorRef>jar-with-dependencies</descriptorRef>  
    16                         </descriptorRefs>  
    17                     </configuration>  
    18                 </plugin>  
    19             </plugins>  
    20         </build>

    三、如果不想包含依赖的jar包,可以把<build>里面的代码替换成如下code:

     1 <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->  
     2             <plugin>  
     3                 <groupId>org.apache.maven.plugins</groupId>  
     4                 <artifactId>maven-jar-plugin</artifactId>  
     5                 <configuration>  
     6                     <archive>  
     7                         <manifest>  
     8                             <addClasspath>true</addClasspath>  
     9                             <classpathPrefix>lib/</classpathPrefix>  
    10                             <mainClass>com.xxx.uploadFile</mainClass>  
    11                         </manifest>  
    12                     </archive>  
    13                 </configuration>  
    14             </plugin>  
    15             <!-- 拷贝依赖的jar包到lib目录 -->  
    16             <plugin>  
    17                 <groupId>org.apache.maven.plugins</groupId>  
    18                 <artifactId>maven-dependency-plugin</artifactId>  
    19                 <executions>  
    20                     <execution>  
    21                         <id>copy</id>  
    22                         <phase>package</phase>  
    23                         <goals>  
    24                             <goal>copy-dependencies</goal>  
    25                         </goals>  
    26                         <configuration>  
    27                             <outputDirectory>  
    28                                 ${project.build.directory}/lib  
    29                             </outputDirectory>  
    30                         </configuration>  
    31                     </execution>  
    32                 </executions>  
    33             </plugin>

    四、只包含部分依赖jar包

    如果想只包含部分依赖jar包

    比如说,想做一个工具jar包,依赖公共jar和自己本地jar包,本地jar包需要解压成class打到jar包内,而依赖的公共jar包则不需要。

    剔除公共jar包 可以用<scope>

    <scope>的值的含义:
    compile,缺省值,适用于所有阶段,会随着项目一起发布。 
    provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。 
    runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 
    test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
    system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。

    编译的时候采用 compile

    1 <dependency>
    2      <groupId>log4j</groupId>
    3      <artifactId>log4j</artifactId>
    4      <version>1.2.17</version>
    5      <scope>complie</scope>
    6      <optional>true</optional>
    7 </dependency>

    在用package打包的时候,改成test,生成的jar包里就不会有该jar包的类了。

    1 <dependency>
    2      <groupId>log4j</groupId>
    3      <artifactId>log4j</artifactId>
    4      <version>1.2.17</version>
    5      <scope>test</scope>
    6      <optional>true</optional>
    7 </dependency>
  • 相关阅读:
    PHP基本的语法以及和Java的差别
    Linux 性能測试工具
    【Oracle 集群】Linux下Oracle RAC集群搭建之Oracle DataBase安装(八)
    【Oracle 集群】Oracle 11G RAC教程之集群安装(七)
    【Oracle 集群】11G RAC 知识图文详细教程之RAC在LINUX上使用NFS安装前准备(六)
    【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 特殊问题和实战经验(五)
    【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之缓存融合技术和主要后台进程(四)
    【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之RAC 工作原理和相关组件(三)
    Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之ORACLE集群概念和原理(二)
    【Oracle 集群】ORACLE DATABASE 11G RAC 知识图文详细教程之集群概念介绍(一)
  • 原文地址:https://www.cnblogs.com/ngy0217/p/9011053.html
Copyright © 2011-2022 走看看