1. 程式人生 > >Maven常用外掛集合

Maven常用外掛集合

在這裡記錄常用的外掛,以備用時可快速查詢,會持續更新

1. maven-compile-plugin

    在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

      <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
      <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>