出自:https://www.cnblogs.com/zhangxh20/p/6298062.html

maven-compiler-plugin

编译Java源码,一般只需设置编译的jdk版本

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-compiler-plugin</artifactId>
  4. <version>3.6.0</version>
  5. <configuration>
  6. <source>1.8</source>
  7. <target>1.8</target>
  8. </configuration>
  9. </plugin>

或者在properties设置jdk版本

  1. <properties>
  2. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3. <maven.compiler.source>1.8</maven.compiler.source>
  4. <maven.compiler.target>1.8</maven.compiler.target>
  5. </properties>

maven-dependency-plugin

用于复制依赖的jar包到指定的文件夹里

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-dependency-plugin</artifactId>
  4. <version>2.10</version>
  5. <executions>
  6. <execution>
  7. <id>copy-dependencies</id>
  8. <phase>package</phase>
  9. <goals>
  10. <goal>copy-dependencies</goal>
  11. </goals>
  12. <configuration>
  13. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  14. </configuration>
  15. </execution>
  16. </executions>
  17. </plugin>

maven-jar-plugin

打成jar时,设定manifest的参数,比如指定运行的Main class,还有依赖的jar包,加入classpath中

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-jar-plugin</artifactId>
  4. <version>2.4</version>
  5. <configuration>
  6. <archive>
  7. <manifest>
  8. <addClasspath>true</addClasspath>
  9. <classpathPrefix>/data/lib</classpathPrefix>
  10. <mainClass>com.zhang.spring.App</mainClass>
  11. </manifest>
  12. </archive>
  13. </configuration>
  14. </plugin>

maven-antrun-plugin

在maven中运行Ant任务,比如在打包阶段,对文件进行复制

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-antrun-plugin</artifactId>
  4. <version>1.7</version>
  5. <executions>
  6. <execution>
  7. <phase>package</phase>
  8. <goals>
  9. <goal>run</goal>
  10. </goals>
  11. <configuration>
  12. <target name="copy">
  13. <delete>
  14. <fileset dir="target" includes="*.properties"></fileset>
  15. </delete>
  16. <copy todir="target">
  17. <fileset dir="files"></fileset>
  18. </copy>
  19. </target>
  20. </configuration>
  21. </execution>
  22. </executions>
  23. </plugin>

wagon-maven-plugin

用于一键部署,把本地打包的jar文件,上传到远程服务器上,并执行服务器上的shell命令

  1. <plugin>
  2. <groupId>org.codehaus.mojo</groupId>
  3. <artifactId>wagon-maven-plugin</artifactId>
  4. <version>1.0</version>
  5. <configuration>
  6. <serverId>crawler</serverId>
  7. <fromDir>target</fromDir>
  8. <includes>*.jar,*.properties,*.sh</includes>
  9. <url>sftp://59.110.162.178/home/zhangxianhe</url>
  10. <commands>
  11. <command>chmod 755 /home/zhangxianhe/update.sh</command>
  12. <command>/home/zhangxianhe/update.sh</command>
  13. </commands>
  14. <displayCommandOutputs>true</displayCommandOutputs>
  15. </configuration>
  16. </plugin>

tomcat7-maven-plugin

用于远程部署Java Web项目

  1. <plugin>
  2. <groupId>org.apache.tomcat.maven</groupId>
  3. <artifactId>tomcat7-maven-plugin</artifactId>
  4. <version>2.2</version>
  5. <configuration>
  6. <url>http://59.110.162.178:8080/manager/text</url>
  7. <username>linjinbin</username>
  8. <password>linjinbin</password>
  9. </configuration>
  10. </plugin>

maven-shade-plugin

用于把多个jar包,打成1个jar包

一般Java项目都会依赖其他第三方jar包,最终打包时,希望把其他jar包包含在一个jar包里

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-shade-plugin</artifactId>
  4. <version>2.4.3</version>
  5. <executions>
  6. <execution>
  7. <phase>package</phase>
  8. <goals>
  9. <goal>shade</goal>
  10. </goals>
  11. <configuration>
  12. <transformers>
  13. <transformer
  14. implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  15. <manifestEntries>
  16. <Main-Class>com.meiyou.topword.App</Main-Class>
  17. <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
  18. <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
  19. </manifestEntries>
  20. </transformer>
  21. </transformers>
  22. </configuration>
  23. </execution>
  24. </executions>
  25. </plugin>

maven-source-plugin

将项目源代码打包成一个jar包(是java文件打包)

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-source-plugin</artifactId>
  4. <configuration>
  5. <attach>true</attach>
  6. </configuration>
  7. <executions>
  8. <execution>
  9. <phase>package</phase>
  10. <goals>
  11. <goal>jar-no-fork</goal>
  12. </goals>
  13. </execution>
  14. </executions>
  15. </plugin>

maven-assembly-plugin

根据package.xml生成一个特别的包

  1. <plugin>
  2. <artifactId>maven-assembly-plugin</artifactId>
  3. <configuration>
  4. <appendAssemblyId>false</appendAssemblyId>
  5. <descriptors>
  6. <descriptor>src/main/build/package.xml</descriptor>
  7. </descriptors>
  8. </configuration>
  9. <executions>
  10. <execution>
  11. <id>make-assembly</id>
  12. <phase>package</phase>
  13. <goals>
  14. <goal>single</goal>
  15. </goals>
  16. </execution>
  17. </executions>
  18. </plugin>

Maven的几个常用plugin的更多相关文章

  1. (五)Maven目录结构及常用命令说明

    前面提到的部分知识有涉及到Maven目录结构与Maven常用的一些命令,在这里专门给大家做个简单的介绍. 1.Maven目录结构说明 Maven总体目录结构如下图: bin目录:该目录包含了mvn运行 ...

  2. Maven系列(一)plugin

    Maven系列(一)plugin maven-compiler-plugin 使用 mvn compile 命令,出现错误: 编码 GBK 的不可映射字符而不能编译.这是因为代码或注释中存在中文引起的 ...

  3. Maven 教程(5)— Maven目录结构及常用命令说明

    原文地址:https://blog.csdn.net/liupeifeng3514/article/details/79543159 1.Maven目录结构说明 Maven总体目录结构如下图: bin ...

  4. maven一键构造及常用命令

    maven一键构造及常用命令 1.maven的一键构建 我们不再使用本地的Tomcat对项目进行编译.测试.运行.打包.安装.部署等一系列过程,而是使用maven自身集成的Tomcat插件来完成这些操 ...

  5. maven profiles、filters、resources学习笔记 及 常用 plugin demo

    这里只记了学习以下博客后,自己做的一个总结. 来源:http://blog.csdn.net/fengchao2016/article/details/72726101 profiles定义了一些不同 ...

  6. JAVA记录-maven JDK配置和常用操作

    1.pom.xml加入(JDK编译器配置) <build> <finalName>项目名</finalName> <plugins> <plugi ...

  7. Maven构建应用程序常用配置(转)

    来自:http://shiyanjun.cn/archives/180.html 使用Maven来构建应用程序,可以非常方便地管理应用相关的资源.众所周知,应用程序中涉及到的一些依赖关系,如Java应 ...

  8. maven Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repositories 解决

    报错:Error resolving version for plugin 'org.apache.maven.plugins:maven-eclipse-plugin' from the repos ...

  9. Maven中pom.xml常用元素说明

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

随机推荐

  1. 使用lua graphql 模块让openresty 支持graphql api

      graphql 是一个很不错的api 查询标准语言,已经有一个lua 的版本支持graphql 项目使用docker&&docker-compose 运行 环境准备 模块安装 lu ...

  2. mysql 变量名称的使用不当的一个错误

    对于开发来说重要的是按照规范进行开发. 昨天自己在进行开发测试的时候,编写mysql 的一个存储过程 ,代码是比较简单的 就是根据名称查询对应的数据并返回 DELIMITER // CREATE PR ...

  3. jquery append、prepend、before等等

    1.jQuery append() 方法 jQuery append() 方法在被选元素的结尾插入内容. 实例 复制代码代码如下: $("p").append("Some ...

  4. java 多线程之:join() 方法

    join()介绍 join() 定义在java.lang.Thread中. join() 的作用:让"主线程"等待"子线程"结束之后才能继续运行.

  5. git 知识点

    git 删除远程已经推送过的文件或者文件夹 git rm -r --cached [文件或文件夹] git status git add . git commit -m '删除远程仓库文件,本地仓库和 ...

  6. gitlab使用外部的postgresql、外部的redis服务器

    postgresql创建用户 su - postgres psql create role gitlab login encrypted password 'pass';\du ;显示用户 postg ...

  7. ES(1): Creat linux VM on Azure

    本章记录在ES集群之前的环境准备工作,主要包含的内容如下: 目录: 创建linux虚拟机 启用root用户 创建linux虚拟机 首先创建一个云服务 按向导创建云服务名称,如下 创建虚拟机, 第二步: ...

  8. 杂项:Nuget

    ylbtech-杂项:Nuget Nuget是一个.NET平台下的开源的项目,它是Visual Studio的扩展.在使用Visual Studio开发基于.NET Framework的应用时,Nug ...

  9. MySQL excel导入

    说明: 1 因在测试发现如果用SQLyog导入数据需要下载excel驱动,因而选择Navicat 2 之前选择excel文件为xlsx 发现Navicat识别不了,因而转存为xls文件,测试OK 1  ...

  10. 1062 Talent and Virtue (25 分)

    1062 Talent and Virtue (25 分) About 900 years ago, a Chinese philosopher Sima Guang wrote a history ...