AWS Lambda Jar unable to zip after adding selenium dependencies in pom AWS Lambda Jar unable to zip after adding selenium dependencies in pom selenium selenium

AWS Lambda Jar unable to zip after adding selenium dependencies in pom


Try to tell your dependencies to output zip, maybe jar is messing up with things

Add this to maven-assembly-plugin configuration:

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

For example:

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-assembly-plugin</artifactId>     ...     <configuration>         ...         <formats>            <format>zip</format>         </formats>     </configuration></plugin>

Same is suggested here


I figured it out. The java selenium seemed to cause the major issue. Downgrading to 3.10 fixed the issue although I have no idea why.


The shade plugin combines all dependencies with the developed code and plops them in one Uber JAR. The downside is that it can overwrite resource files, and doesn't play well with signed jars (in my experience at least).

I would recommend moving away from the shade plugin if at all possible.

That said, if you have to use it - you're issue may be with the combining the jar resources. There are many transformers that you can use to resolve this, and you'll need to investigate which one is really needed. I would start with something like this

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-shade-plugin</artifactId>    <version>2.4.3</version>    <configuration>        <shadedArtifactAttached>true</shadedArtifactAttached>        <shadedClassifierName>${executable.classifier}</shadedClassifierName>        <filters>            <filter>                <artifact>*:*</artifact>                <excludes>                    <exclude>META-INF/*.SF</exclude>                    <exclude>META-INF/*.DSA</exclude>                    <exclude>META-INF/*.RSA</exclude>                </excludes>            </filter>        </filters>    </configuration>    <executions>        <execution>            <phase>package</phase>            <goals>                <goal>shade</goal>            </goals>            <configuration>                <transformers>                    <transformer                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />                    <transformer                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">                        <mainClass>fully.qualified.ClassName</mainClass>                    </transformer>                </transformers>            </configuration>        </execution>    </executions></plugin>

You can find more tranformers on the Apache plugin here

The alternative that I would suggest is Spring Boot, which uses the Jar-in-Jar structure with a custom ClassLoader to load classes from the internal jar(s).

This is the easier method due to not having to re-write files as the Shade plugin approach and it handles the dependencies a little better.

<plugin>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-maven-plugin</artifactId>    <version>1.3.6.RELEASE</version>    <configuration>        <classifier>${executable.classifier}</classifier>        <layout>ZIP</layout>        <mainClass>fully.qualified.ClassName</mainClass>    </configuration>    <executions>        <execution>            <phase>package</phase>            <goals>                <goal>repackage</goal>            </goals>        </execution>    </executions></plugin>

Seriously, look at the simpler configuration!

NOTE: Most of this came from my own notes - version numbers may be a little old...