javaspring-bootmavenmaven-assembly-pluginmaven-antrun-plugin

How to fix compression error when repackaging Spring Boot Jar


I need to inject static UI files into an existing Spring Boot executable jar. To do so, I'm pulling the jar as a dependency, and using the maven antrun plugin to:

This all seems to work; however, when I run the Jar, I get the following error:

Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/HdrHistogram-2.1.12.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file

When I inspect the contents of the Jar, everything looks fine (the libs do not seem to be compressed). Any idea of what's going on here or suggestions for a better repackaging solution? Thanks!


Solution

  • I ended up using the exec-maven-plugin and Java jar utility to add the UI files. See code below (the ui files are in the /tmp/resources directory):

    <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>3.0.0</version>
          <executions>
            <execution>
              <id>update-jar</id>
              <phase>package</phase>
              <goals>
                <goal>exec</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <executable>jar</executable>
            <workingDirectory>${project.build.directory}/tmp</workingDirectory>
            <arguments>
              <argument>uf</argument>
              <argument>dependencies/myjar-${version}.jar</argument>
              <argument>resources</argument>
            </arguments>
          </configuration>
        </plugin>