2015-09-17 42 views
0

我有一個Maven JavaScript NodeJS項目。以下是項目結構如何創建一個Maven JavaScript項目的壓縮文物

-- Project 
    -- dist 
    -- node_modules 
    -- src 
    -- target 
    Gruntfile.js 
    gulpfile.js 
    package.json 
    pom.xml 

是否有配置POM,使其構建dist文件夾的壓縮文件,並在輸出對象目錄保存它的方法嗎?

回答

0

這可以使用maven-assembly-plugin。這是一個非常通用的插件,可以用來創建項目的自定義組件。

它通過assembly.xml文件進行配置。對於你的情況下,配置是:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> 
    <id>dist</id> 
    <formats> 
    <format>zip</format> <!-- create a zip archive --> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <directory>dist</directory> <!-- source is the "dist" folder --> 
     <outputDirectory>/</outputDirectory> <!-- target is the root of the archive --> 
    </fileSet> 
    </fileSets> 
</assembly> 

此文件的典型位置將是src/main/assembly/assembly.xml。然後,POM將包含:

<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.5.5</version> 
      <configuration> 
       <descriptors> 
        <descriptor>src/main/assembly/assembly.xml</descriptor> 
       </descriptors> 
      </configuration> 
      <executions> 
       <execution> 
        <id>assembly-dist</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

調用mvn clean package後,target文件夾將包含此插件生成的壓縮文件。