Maven

maven中配置插件

2017-02-27  本文已影响71人  ibyr

maven中自定义插件。

1.maven pom.xml 中配置jetty插件

<build>
      <!-- will be final-app-name.war -->
      <finalName>final-app-name</finalName> 
      <plugins>
          <plugin>
              <!-- a plugin must have minimum config of groupId, artifactId, version -->
              <groupId>org.mortbay.jetty</groupId>
              <artifactId>maven-jetty-plugin</artifactId>
              <version>6.1.7</version>
              <configuration>
                  <!-- interval of jetty scanning the project -->
                  <scanIntervalSeconds>10</scanIntervalSeconds>
                  <!-- contextpath of web. Users can visit by http://hostname:port/test/  -->
                  <contextPath>/test</contextPath>
                  <connectors>
                      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                          <port>8080</port>
                          <maxIdleTime>60000</maxIdleTime>
                      </connector>
                  </connectors>
              </configuration>
          </plugin>
      </plugins>
</build>

2.pom.xml 中配置maven-compiler-plugin插件

The Compiler Plugin is used to compile the sources of your project.
Default source and target jdk is 1.5, independently the jdk you run.
参考链接-Maven官网

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.6</source> <!-- 源代码使用的开发版本 -->
        <target>1.6</target> <!-- 需要生成的目标class文件的编译版本 -->
        <!-- 一般而言,target与source是保持一致的,但是,有时候为了让程序能在其他版本的jdk中运行(对于低版本目标jdk,源代码中需要没有使用低版本jdk中不支持的语法),会存在target不同于source的情况 -->
    
        <!-- 这下面的是可选项 -->
        <meminitial>128m</meminitial>
        <maxmem>512m</maxmem>
        <fork>true</fork> <!-- fork is enable,用于明确表示编译版本配置的可用 --> 
        <compilerVersion>1.3</compilerVersion>        
    </configuration>
</plugin>

The same effect with:

<!-- pom.xml -->
<project>
  [...]
  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  [...]
</project>

参考链接-Maven官网
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html


3.pom.xml中配置maven-war-plugin插件,用来打war包。

 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
            <webResources>
                <resource>
                    <!-- 元配置文件的目录,相对于pom.xml文件的路径。-->
                    <!--在打包的时候,将directory中的文件全部搬运到targetPath。 -->
                    <directory>src/main/resources</directory>
                    <!-- 目标路径-->
                    <targetPath>WEB-INF</targetPath>
                </resource>
            </webRespurces>
            <!--/sample/servlet/container/deploy/directory-->
           <webappDirectory>
                <!-- 自定义的 ${project.build.directory}/${project.artifactId}-->
                /sample/servlet/container/deploy/directory
           </webappDirectory>
        </configuration>
      </plugin>

Note:
The default resource directory for all Maven projects is src/main/resources which will end up in target/classes and in WEB-INF/classes in the WAR.

参考链接-Maven官网

[未完。]

上一篇 下一篇

猜你喜欢

热点阅读