Issue
I have built awsblog-queueing-1.0.0.jar
with a size of 15MB.
The build for the entire project, which I also want the above JAR included in, however is only 7 MB.
Trying to run the resulting JAR gives me:
com/awsblog/queueing/appdata/ShipmentData: java.lang.NoClassDefFoundError
java.lang.NoClassDefFoundError: com/awsblog/queueing/appdata/ShipmentData
at com.test.App.handleRequest(App.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>s3_trigger</artifactId>
<packaging>jar</packaging>
<name>s3_trigger</name>
<version>1.0.0</version>
<properties>
<java.version>1.8</java.version>
<sl4j.version>1.6.1</sl4j.version>
<environment>local</environment>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<build.version>1.0.0</build.version>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</maven.build.timestamp.format>
<build-number>1.0.0</build-number>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</maven.build.timestamp.format>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-core -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.271</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${sl4j.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-events -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>com.awsblog.queueing</groupId>
<artifactId>awsblog-queueing</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>C:/Users/abcd/Desktop/amazon-dynamodb-implementing-priority-queuing-master/target/awsblog-queueing-1.0.0.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE</version>
</extension>
</extensions>
</build>
</project>
Solution
You need to use maven-install-plugin
to include your custom third-party JAR into your final JAR.
Apache Maven has a guide for it but specifically for your case:
- Remove the
scope
&systemPath
XML tags for your third-party dependency from yourpom.xml
file as they are not needed - Run
mvn install:install-file -Dfile=C:/Users/abcd/Desktop/amazon-dynamodb-implementing-priority-queuing-master/target/awsblog-queueing-1.0.0.jar -DgroupId=com.awsblog.queueing -DartifactId=awsblog-queueing -Dversion=1.0.0
to install the local JAR in your local repository - Run
mvn clean package
Answered By - Ermiya Eskandary
Answer Checked By - Willingham (JavaFixing Volunteer)