[Vuejs]-Zip a file with maven to a NO java application directory

0👍

You mentioned, that you are already using npm to build your Vue app. There are libraries for npm available for zipping. You could e.g. do something like this:

const fs = require('fs');
const archiver = require('archiver');

const archive = archiver('zip', {
  zlib: { level: 9 }
});

const filename = "./output.zip";
const fileOutput = fs.createWriteStream(filename);

fileOutput.on('close', function() {
  console.info('ZIP file created. ' + archive.pointer() + ' total Bytes.');
});

archive.pipe(fileOutput);
archive.directory('./input-directory', '/');

archive.on('error', function(error) {
  throw error;
});

archive.finalize();

This assumes, that the output of your build process is stored in a dist folder on your file system and that you have access to the filesystem.

There are more examples of archiver in the official docs: https://github.com/archiverjs/node-archiver

0👍

You may build a zip file using the maven-assembly-plugin with an assembly descriptor.

The assembly descriptor goes in the project’s src/assembly directory, named something like my-zip-format.xml. You’ll need to customize the content to include the files needed but this is the idea.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>my-zip</id>

    <formats>
      <format>zip</format>
    </formats>

    <fileSets>
      <fileSet>
        <directory>path/to/input/dir</directory>
        <outputDirectory>name-of-output-dir</outputDirectory>
        <directoryMode>0750</directoryMode>
        <fileMode>0640</fileMode>
        <lineEnding>unix</lineEnding>
      </fileSet>
    </fileSets>
</assembly>

Then, tell the POM to use the assembly:

....
<plugins>
  <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version><pluginVersionHere></version>
    <executions>
      <execution>
        <id>make-zip</id>
        <phase>package</phase>
        <goals>
           <goal>single</goal>
        </goals>
        <configuration>
          <descriptors>
            <descriptor>src/assembly/my-zip-format.xml</descriptor>
          </descriptors>
        </configuration>
        ...

Documentation goes into a lot more detail, and there are plenty of SO questions/answers about assembly plugin nuances as well.

Leave a comment