4

I'm building a uber jarfile but slimmed with the <minimizeJar>true</minimizeJar> option to the maven shade plugin.

I get this error with that option set:

$> java -jar target/lambda-send-email-1.0-SNAPSHOT.jar

Exception in thread "main" java.lang.NoClassDefFoundError: com.amazonaws.AmazonWebServiceClient
    at com.kilsbo.lambda.CreateAndSendEmail.addEmailToDynamo(CreateAndSendEmail.java:148)
    at com.kilsbo.lambda.CreateAndSendEmail.handleRequest(CreateAndSendEmail.java:125)
    at com.kilsbo.lambda.CreateAndSendEmail.main(CreateAndSendEmail.java:43)

However, with the big bloated jar (minimizeJar set to false), it works.

I've unzipped the minimilised jar and the classes needed are actually included.

unzippedJar/$> file com/amazonaws/AmazonWebServiceClient.class 

com/amazonaws/AmazonWebServiceClient.class: compiled Java class data, version 50.0 (Java 1.6)

So, I'm thinking that there's a classpath issue here but I haven't really found a solution for it reading the maven shade plugin docs.

My plugin setup in the pom:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.kilsbo.lambda.CreateAndSendEmail</mainClass>
                    </transformer>
                </transformers>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <minimizeJar>true</minimizeJar>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Any suggestions?

Wrench
  • 4,070
  • 4
  • 34
  • 46

1 Answers1

2

If com/amazonaws/AmazonWebServiceClient.class is present in the same jar with your class files that are being found and executed, then there's no classpath issue. The classloader found your class to load.

More likely it is the case that some class that AmazonWebServiceClient depends on cannot be found. Unfortunately, the JVM still throws this slightly misleading error message. For example, check the source to AmazonWebServiceClient to see if it extends another class or has any imports that aren't in your shaded uber-jar. One common mistake is that any

<scope>provided<scope>
dependencies in your pom will not be shaded in. Perhaps AmazonWebServiceClient extends from something in a different Amazon jar that is not being shaded in.
steve_ash
  • 1,184
  • 1
  • 10
  • 16