zoukankan      html  css  js  c++  java
  • MAVEN学习(六)--maven常用插件

    我们使用maven做一些日常的工作开发的时候,无非是想利用这个工具带来的一些便利。比如它带来的依赖管理,方便我们打包和部署运行。这里几个常见的插件就是和这些工程中常用的步骤相关。

    maven-compile-plugin

        这个插件就如同名字所显示的这样,用来编译源代码的。最开始碰到这个插件是在于有的时候我们下载了一些工程需要编译的时候,比如我们输入命令:mvn install ,但是系统编译的时候报错了,错误的信息如下:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project springJMS: Compilation failure: Compilation failure:  
    [ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/huangbowen/net/jms/MessageSender.java:[6,1] error: annotations are not supported in -source 1.3  
    [ERROR]   
    [ERROR] (use -source 5 or higher to enable annotations)  
    [ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/net/EmbedBrokerApp.java:[5,7] error: static import declarations are not supported in -source 1.3  
    [ERROR] -> [Help 1]  
    [ERROR]   
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.  
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.  
    [ERROR]   
    [ERROR] For more information about the errors and possible solutions, please read the following articles:  
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

        从错误显示的信息我们就可以看出,这是因为编译的时候是默认用的javac 1.3版本的,太老了不支持代码里的特性。为了修改这个问题,我们需要设置编译器的版本。解决这个问题的办法也比较简单,就是直接在后面的插件部分增加如下的插件,比如如下部分,将编译器的版本设定为1.6:

    <build>  
          <plugins>  
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <version>2.3.2</version>  
                <configuration>  
              <encoding>UTF-8</encoding> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build>
    <!-- 编译插件 -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
            <!-- 源码风格使用1.7风格 -->
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
            <!--必须添加compilerArgument配置,才能使用JFinal的Controller方法带参数的功能-->
            <compilerArgument>-parameters</compilerArgument>
            <!--<compilerArgs>-->
                <!--<compilerArg>-parameters</compilerArg>-->
            <!--</compilerArgs>-->
            <!-- 编译跳过代码编译类 -->
            <excludes>
                <!-- 排除应用程序编译类 -->
                <exclude>**/ApplicationCodeGenerator.java</exclude>
            </excludes>
        </configuration>
    </plugin>
    <plugins> 
        <!-- Maven 编译错误 Dynamic Web Module 3.0 requires Java 1.6 or newer 解决方案 -->
            <!-- define the project compile level ,指定编译级别1.7--> 
            <plugin> 
                <groupId>org.apache.maven.plugins</groupId> 
                <artifactId>maven-compiler-plugin</artifactId> 
                <version>2.3.2</version> 
                <configuration> 
                    <source>1.7</source> 
                    <target>1.7</target> 
                </configuration> 
            </plugin> 
        </plugins> 

    以下几种插件都是maven项目中常用插件,具体用到时候可以网上自行查找使用方法,在此不一一详解:

    maven-resources-plugin     配置资源打包

    maven-surefire-plugin  测试

    jetty-maven-plugin  运行jetty

    maven-jar-plugin  打jar包(maven-jar-plugin生成的包只包含class文件,和maven-resources-plugin、maven-dependency-plugin配合使用)

    maven-dependency-plugin  复制依赖jar包到指定目录

    maven-war-plugin  打可执行war包(工作中发现3.0.0的maven-war-plugin插件做分环境打包时候有问题,2.0.2的正常)

    maven-assembly-plugin  打可执行包(有bug,可能会jar包冲突,不推荐)

    maven-shade-plugin  打可执行包(推荐) 

    spring-boot-maven-plugin  springBoot项目打包(先执行maven普通打jar包命令,将生成的jar包名称增加后缀.orginal,再在此jar包基础上,生成包含所有配置文件和依赖包的可执行jar包)

    maven-source-plugin  生成源码包

    cobertura-maven-plugin  测试覆盖率

    sonar-maven-plugin  sonar代码检测

    个人理解,如有错误,欢迎指正!
  • 相关阅读:
    Spring杂谈 | 什么是ObjectFactory?什么是ObjectProvider?
    一次相亲经历,我彻底搞懂了什么叫阻塞非阻塞,同步异步
    Spring杂谈 | 你真的了解泛型吗?从java的Type到Spring的ResolvableType
    Spring官网阅读(十二)ApplicationContext详解(中)
    Spring官网阅读(十一)ApplicationContext详细介绍(上)
    Spring官网阅读(十)Spring中Bean的生命周期(下)
    Spring官网阅读(九)Spring中Bean的生命周期(上)
    influxDB 0.9 C# 读写类
    使用HAProxy实现sql server读库的负载均衡
    influxdb基本操作
  • 原文地址:https://www.cnblogs.com/gllegolas/p/11611455.html
Copyright © 2011-2022 走看看