Maven常用配置

1.统一项目字符集

<properties>  
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties>

2.dependency scope配置

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

3.插件配置

3.1 JDK插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

3.2资源文件配置

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
        <encoding>UTF-8</encoding>    <!--配置资源文件编码-->
    </configuration>
</plugin>

3.3打包

maven-assembly-plugin的用途是制作项目分发包,该分发包可能包含了项目的可执行文件、源代码、readme、平台脚本等等

3.4 jetty配置

<plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.6</version>
                <configuration>
                    <contextPath>/</contextPath>
                    <scanIntervalSeconds>3</scanIntervalSeconds>
                    <scanTargetPatterns>
                        <scanTargetPattern>
                            <directory>src/main/webapp/WEB-INF</directory>
                            <excludes>
                                <exclude>**/*.jsp</exclude>
                            </excludes>
                            <includes>
                                <include>**/*.properties</include>
                                <include>**/*.xml</include>
                            </includes>
                        </scanTargetPattern>
                    </scanTargetPatterns>
                    <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
                        <filename>target/yyyy_mm_dd.request.log</filename>
                        <retainDays>90</retainDays>
                        <append>true</append>
                        <extended>false</extended>
                        <logTimeZone>GMT</logTimeZone>
                    </requestLog>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>80</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                </configuration>
            </plugin>

3.5生成java文档

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>javadoc</goal>
                        </goals>
                        <phase>compile</phase>
                    </execution>
                </executions>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <verbose>false</verbose>
                    <show>public</show>
                    <subpackages>com.pwrd.mobileqa.assist.resource</subpackages>
                    <doclet>com.sun.jersey.wadl.resourcedoc.ResourceDoclet</doclet>
                    <docletPath>${path.separator}${project.build.outputDirectory}</docletPath>
                    <docletArtifacts> <!--解析项目生成javadoc需要的依赖-->
                       <docletArtifact>
                           <groupId>xerces</groupId>
                           <artifactId>xercesImpl</artifactId>
                           <version>2.6.1</version>
                       </docletArtifact>
             ......
                    </docletArtifacts>
                    <!--  the following option is required as a work around for
                         version 2.5 of the javadoc plugin which will be used
                         by a maven version > 2.0.9-->
                    <useStandardDocletOptions>false</useStandardDocletOptions>
                    <additionalparam>-output ${project.build.outputDirectory}/resourcedoc.xml</additionalparam>
                </configuration>
            </plugin>

3.6生成mybatis映射

默认会在根目录查找并使用名为mybatis-config.xml的配置文件。

           <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
              <version>1.3.0</version>
              <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
              </configuration>
             <executions>
                <execution>
                  <id>Generate MyBatis Artifacts</id>
                  <goals>
                    <goal>generate</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>

3.7测试覆盖率计算

基于jcoverage,原理是对class文件插桩,然后执行测试并生成覆盖率报告

<reporting>
    <outputDirectory>target/site</outputDirectory>
      <plugins>
          <plugin>
              <groupId>org.codehaus.mojo</groupId>
              <artifactId>cobertura-maven-plugin</artifactId>
          </plugin>
      </plugins>  
  </reporting>

运行 mvn cobertura:cobertura 将会插桩class文件、测试、生成覆盖率报告。

导出含主类的jar包

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-jar-plugin</artifactId>  
    <version>2.4</version>  
    <configuration>
    <excludes>  <!--打包时要排除的文件-->
        <exclude>agent.properties</exclude>  
    </excludes>
       <archive>  
           <manifest>  
               <addClasspath>true</addClasspath>  
<!--           <classpathPrefix>lib/</classpathPrefix>   -->
               <mainClass>com.demo.HelloWorld</mainClass>  
            </manifest>  
         </archive>  
      </configuration>  
   </plugin> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值