Maven常用插件集合

来源:互联网 发布:淘宝店铺首页无法打开 编辑:程序博客网 时间:2024/06/10 23:20

在这里记录常用的插件,以备用时可快速查询,会持续更新

1. maven-compile-plugin

    官方介绍 http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

    在pom.xml文件中默认编译级别是1.5,如果需改成1.6,可以在pom.xml中增加如下配置

<plugin>

    <artifactId>maven-compiler-plugin</artifactId>
    <extensions>true</extensions> 
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>


extensions表示继续默认的配置,这里只是修改了编译jdk为1.6


2. maven-bundle-plugin
    官方介绍 http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
         <instructions>
                <Export-Package>com.my.company.api</Export-Package>
                <Private-Package>com.my.company.*</Private-Package>
                <Bundle-Activator>com.my.company.Activator</Bundle-Activator>
          </instructions>
    </configuration>
</plugin>


3. maven-dependency-plugin

      官方介绍 http://maven.apache.org/plugins/maven-dependency-plugin/

      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-dependency-plugin</artifactId>        <version>2.8</version>        <executions>          <execution>            <id>copy-dependencies</id>            <phase>package</phase>            <goals>              <goal>copy-dependencies</goal>            </goals>            <configuration>              <outputDirectory>${project.build.directory}/lib</outputDirectory>              <overWriteReleases>false</overWriteReleases>              <overWriteSnapshots>true</overWriteSnapshots>
      <overWriteIfNewer>true<overWriterIfNewer>
              <excludeArtifactIds>servlet-api<excludeArtifactIds>            </configuration>          </execution>        </executions>      </plugin>
   这个配置可以把所有的依赖拷贝到lib目录下,通过maven-jar-plugin就可以将lib下面的jar包打到最终的jar里面
      
      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-jar-plugin</artifactId>        <executions>          <execution>            <id>jar</id>            <phase>package</phase>            <goals>              <goal>jar</goal>            </goals>            <configuration>              <classesDirectory>${project.build.directory}/lib</classesDirectory>
            </configuration>          </execution>        </executions>      </plugin>
4. maven-war-plugin
   官方介绍:http://maven.apache.org/plugins/maven-war-plugin/
   
      <plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-war-plugin</artifactId>        <version>2.3</version>        <configuration>          <webResources>            <resource>              <!-- this is relative to the pom.xml directory -->              <directory>resource2</directory><!--打包时包含这个目录的内容-->
              <excludes> <!--排除一些目录-->                <exclude>**/properties</exclude>              </excludes>
</resource>  
          </webResources>        
        </configuration>      
     </plugin>

原创粉丝点击