简体   繁体   English

如何创建Maven JavaScript项目的压缩工件

[英]how to create a zipped artifact of a maven javascript project

I have a Maven JavaScript NodeJS project. 我有一个Maven JavaScript NodeJS项目。 Following is the project structure 以下是项目结构

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

Is there a way to configure the pom so that it builds a zipped file of the dist folder and saves it in the output target directory? 有没有一种方法可以配置pom,以便它构建dist文件夹的压缩文件并将其保存在输出目标目录中?

This is possible using the maven-assembly-plugin . 使用maven-assembly-plugin可以做到这一点。 This is a very general plugin that can used to create a custom assembly of a project. 这是一个非常通用的插件,可用于创建项目的自定义程序集。

It is configured through an assembly.xml file. 它是通过assembly.xml文件配置的。 For your case, the configuration would be: 对于您的情况,配置为:

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

The typical location for this file would be src/main/assembly/assembly.xml . 该文件的典型位置是src/main/assembly/assembly.xml Then, the POM would contain: 然后,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>

After invoking mvn clean package , the target folder will contain the zip file produced by this plugin. 调用mvn clean packagetarget文件夹将包含此插件生成的zip文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM