0
votes

I am creating building a jar which will also include its dependencies. I am using maven shade plugin for this. But getting Caused by: java.util.zip.ZipException: invalid LOC header error while building. I tried excluding the transitive dependency as shown below still getting error.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tlt.idk</groupId>
<artifactId>saba-user-import</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>CSVSabaUserImport</name>
<dependencies>
    <dependency>
        <groupId>com.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>3.3</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons.lang3</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
     <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.1.1</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
         <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>ImportCsv</mainClass>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
    </plugins>
</build>

Caused by: java.io.IOException: Problem shading JAR C:\Users\Admin.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar entry META-INF/LICENSE.txt: java.util.zip.ZipException: invalid LOC header (bad signature) at org.apache.maven.plugins.shade.DefaultShader.shadeJars(DefaultShader.java:197) at org.apache.maven.plugins.shade.DefaultShader.shade(DefaultShader.java:106) at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute(ShadeMojo.java:442) ... 21 more Caused by: java.util.zip.ZipException: invalid LOC header (bad signature)

Any help in this regard will be appreciated.

1
Would you please be able to post your full pom.xml to see if there's anything else that may be related to this problem? Also, have you tried mvn dependency:tree to see if any other dependency pulls in apache-commons? Just want to eliminate some of the more straightforward possibilities.Justin Albano
Post also full stack trace including all information ..with Maven Shade 3.1.1 there should be supplemental information about the wrong jar file...Furthermore I recommend to fail your build if checksums are wrong this needs to be activated via settings.xml file (checksum policy)..khmarbaise
@JustinAlbano posted full pom.. already tried mvn dependecy:tree. opencvs is having it as trasitive depedency.Vikas Yadav
@khmarbaise commons.lang3 is causing the isseVikas Yadav
try with deleting the commons-lang3 jar from local maven repo and let it download again.saurav

1 Answers

0
votes

I guess there was an error downloading the dependency. This happend quite often when eclipse downloaded the dependencies for me.

Delete the corrupted artifact from your maven cache (located in C:\Users\<username>\.m2\respository).