Maven系列(一)plugin

maven-compiler-plugin

使用 mvn compile 命令,出现错误: 编码 GBK 的不可映射字符而不能编译。这是因为代码或注释中存在中文引起的,一般在 IDE 中会自动处理编译时的字符集,就不会碰到这个错误。这个错误是在生成代码后,其中自动加上了中文注释,手动删除中文注释处理这个问题太麻烦。这个错误是在命令行执行编译命令才出现的,需要设置编译的字符集,设置方式是:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

其中:

  • encoding 如果不设置的话会用本地操作系统的编码来编译文件

maven-resources-plugin

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

其中:

  • encoding 设置资源文件的编码方式

maven-dependency-plugin

拷贝依赖包 mvn dependency:copy-dependencies,默认会拷到项目的 target\dependency 目录,想要复制到自定义的目录比如 target/lib 目录下,需要在 pom.xml 文件中添加设置覆盖默认设置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>true</stripVersion>
</configuration>
</plugin>

其中:

  • outputDirectory ${project.build.directory}是maven变量,表示target目录。如果不写的话,将在根目录下创建 target\dependency 目录;
  • excludeTransitive 表示是否不包含间接依赖的包;
  • stripVersion 表示复制的jar文件去掉版本信息。

如果需要在其他过程,比如 package 中加入 copy-dependencies,需要在该 plugin 标签中这样设置:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>

maven-jar-plugin

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.binarylei.network.netty.helloworld.Server</mainClass>
<!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
<useUniqueVersions>false</useUniqueVersions>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
</configuration>
</plugin>

maven-javadoc-plugin

通过 maven-javadoc-plugin 生产文档包插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

maven-source-plugin

通过 maven-source-plugin 生产源码包插件

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>

tomcat7-maven-plugin

tomcat7:run 本地运行项目

 <plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--此端口表示本地项目运行的端口-->
<port>9999</port>
<!--利用tomcat manager部署-->
<url>http://192.168.0.11:8080/manager/text/</url>
<server>tomcat-deploy</server>
<!--以下用户名和密码需要在tomca-user.xml文件中配置如下内容
<role rolename="tomcat"/>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<role rolename="manager-jmx"/>
<role rolename="manager-gui"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="tomcat" roles="admin,admin-gui,manager,manager-gui,manager-script,manager-status,manager-jmx"/>
第一次部署用tomcat7:deploy命令,前提是tomcat必须先启动,然后tomcat webapps目录下manager目录还在
tomcat7:redeploy重新部署
tomcat7:undeploy删除部署
-->
<username>tomcat</username>
<password>tomcat</password>
<!--项目部署访问路径-->
<path>/${project.name}</path>
</configuration>
</plugin>

jetty-maven-plugin

 <plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.8.v20160314</version>
<configuration>
<webAppConfig>
<!-- 指定 root context 在这里指定为${project.artifactId} 即 jetty, 那么访问时就用http://localized:8080/jetty
访问, 如果指定梶为test 就用http://localized:8080/test访问,更多信息,请查看jetty 插件官方文档 -->
<contextPath>/${project.name}</contextPath>
<defaultsDescriptor>src/test/resources/webdefault.xml</defaultsDescriptor>
</webAppConfig>
<stopPort>9966</stopPort>
<stopKey>stop</stopKey>
<stopWait>10</stopWait>
<scanIntervalSeconds>10</scanIntervalSeconds>
<!-- 指定额外需要监控变化的文件或文件夹,主要用于热部署中的识别文件更新 -->
<scanTargetPatterns>
<scanTargetPattern>
<directory>src</directory>
<includes>
<!-- <include>*.java</include> <include>*.properties</include> -->
<include>*.html</include>
<include>*.js</include>
<include>*.css</include>
</includes>
<!-- <excludes> <exclude>**/*.xml</exclude> <exclude>**/myspecial.properties</exclude>
</excludes> -->
</scanTargetPattern>
</scanTargetPatterns>
<!-- 指定监控的扫描时间间隔,0为关闭jetty自身的热部署,主要是为了使用jrebel -->
<!-- <scanIntervalSeconds>0</scanIntervalSeconds> -->
<!-- 指定web页面的文件夹 -->
<webAppSourceDirectory>${project.name}/src/main/webapp</webAppSourceDirectory>
</configuration>
</plugin>

Maven系列(一)plugin的更多相关文章

  1. Maven系列(二)exec-maven-plugin

    Maven系列(二)exec-maven-plugin 1. mvn 命令行运行 # exec:java 不会自动编译代码,你需要手动执行 mvn compile 来完成编译 mvn compile ...

  2. Maven系列第6篇:生命周期和插件详解,此篇看过之后在maven的理解上可以超越同级别90%的人!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第6篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  3. Maven系列第9篇:多环境构建支持,核心开发必备!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第9篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  4. Maven系列(二) -- 将开源库上传到maven仓库私服

    前言 之前简单说了下Maven的搭建,现在跟大家说一下如何将自己的aar传到我们新搭建的maven仓库里面,接下来我们就从最基本的新建一个library开始讲述整个流程,话不多说,让我们把愉快的开始吧 ...

  5. maven系列之二maven项目的创建和maven项目的结构

    maven系列之一简单介绍了maven的基本信息,安装和配置,大家对maven有一个大概的了解,但是在maven项目开发中远远不够,为了进一步了解maven,现在我们介绍maven项目的创建和mave ...

  6. [转]解决Maven报错"Plugin execution not covered by lifecycle configuration"

    [转]解决Maven报错"Plugin execution not covered by lifecycle configuration" 导入Myabtis源码后,POM文件会报 ...

  7. 【连载】Maven系列(四)——配置私服

    相关文章 1.<用起来超爽的Maven——入门篇> 2.<用起来超爽的Maven——进阶篇> 3.<Maven系列(三) 进阶> 一.为什么需要私服 有些公司并不提 ...

  8. Maven系列第8篇:你的maven项目构建太慢了,我实在看不下去,带你一起磨刀!!多数使用maven的人都经常想要的一种功能,但是大多数人都不知道如何使用!!!

    maven系列目标:从入门开始开始掌握一个高级开发所需要的maven技能. 这是maven系列第8篇. 整个maven系列的内容前后是有依赖的,如果之前没有接触过maven,建议从第一篇看起,本文尾部 ...

  9. Maven系列(一) -- maven仓库的搭建

    从今天开始,我要写一个maven系列的文章,以帮助大家来更好的熟悉maven仓库,并且将自己优秀的的代码开源出去,一方面为开源做贡献,另一方面顺便提升自己的知名度,让我们把愉快的开始吧 为什么要搭建m ...

随机推荐

  1. selenium+python自动化93-Chrome报错:Python is likely shutting down

    遇到问题 报错信息:sys.meta_path is None, Python is likely shutting down 1.我的环境: python 3.6 selenium 2.53.6 c ...

  2. 怎么理解Linux软中断?

    1.什么是中断 中断是系统用来响应硬件设备请求的一种机制,它会打断进程的正常调度和执行,然后调用内核中的中断处理程序来响应设备的请求. 2.为什么要有中断呢? "举个生活中的例子" ...

  3. c#面向对象基础5

    字符串  string (1)字符串的不可变性 当给字符串重新赋值时,老值没有被销毁,而是重新开辟了一块新的空间去储存新值<------------------堆中,在栈中地址发生变化重新指向新 ...

  4. 数据结构之线索二叉树——C语言实现

     线索二叉树操作 (1) 线索二叉树的表示:将每个节点中为空的做指针与右指针分别用于指针节点的前驱和后续,即可得到线索二叉树. (2) 分类:先序线索二叉树,中序线索二叉树,后续线索二叉树 (3) 增 ...

  5. 7. myeclipse10反编译插件安装

  6. 34. CentOS-6.3安装配置Apache2.2.6

    安装说明 安装环境:CentOS-6.3安装方式:源码编译安装 软件:httpd-2.2.6.tar.gz  | pcre-8.32.tar.gz | apr-1.4.6.tar.gz | apr-u ...

  7. 前端-CSS-3-高级选择器

    高级选择器 总结: <!-- 总结: 基础选择器: 1.标签选择器 div 2.类选择器 .div1 3.id选择器 #box 4.通配符选择器 * 高级选择器: 1.群组选择器 中间用, .t ...

  8. UI5-文档-4.25-Sorting and Grouping

    为了使我们的发票列表更加用户友好,我们将它按字母顺序排序,而不是仅仅显示来自数据模型的顺序.此外,我们还引入了组,并添加了发布产品的公司,以便更容易使用数据. Preview The list is ...

  9. mysql插入json数据

    data_dict = {"a":1, "b":2}  data_json = json.dumps(data_dict) data_escape = MySQ ...

  10. tomcat APR的配置

    Tomcat 可以使用 APR 来提供超强的可伸缩性和性能,更好地集成本地服务器技术. APR(Apache Portable Runtime) 是一个高可移植库,它是 Apache HTTP Ser ...