When I try to invoke my resource provider in AWS CloudFormation, I receive the following error:
"java.lang.ClassNotFoundException: com.example.package.resource.HandlerWrapper"
Short description
You receive the "java.lang.ClassNotFoundException: com.example.package.resource.HandlerWrapper" error when you're developing or testing a resource provider schema file. You call cfn test or sam local invoke, but the /target/ directory in your project doesn't contain a valid .jar file.
For other errors that are related to using a resource provider, see the following articles:
Resolution
By default, the name of the .jar file is in the organization-service-resource-handler-1.0-SNAPSHOT.jar format and is configured in the pom.xml file in your project's root directory. For example:
<groupId>com.organization.service.resource</groupId>
<artifactId>organization-service-resource-handler</artifactId>
<name>organization-service-resource-handler</name>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
To build your project, run cfn generate. Then, run mvn package. For example:
$ cfn generate
Generated files for Organization::Service::Resource
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] --< software.organization.service.resource:organization-service-resource-handler >--
[INFO] Building organization-service-resource-handler 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.690 s
[INFO] Finished at: 2020-07-14T16:02:47-05:00
[INFO] ------------------------------------------------------------------------
Note: If the build and tests are successful, then mvn creates the necessary**.jar** file in the /target/ directory.
To skip the tests for unit tests that aren't complete, run mvn -Dmaven.test.skip=true package instead of mvn package.
$ cfn generate
Generated files for Organization::Service::Resource
$ mvn package -Dmaven.test.skip=true package
[INFO] Scanning for projects...
[INFO]
[INFO] --< software.organization.service.resource:organization-service-resource-handler >--
[INFO] Building organization-service-resource-handler 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.690 s
[INFO] Finished at: 2020-07-14T16:02:47-05:00
[INFO] ------------------------------------------------------------------------
Tip: You can troubleshoot the tests by navigating to the directory /target/surefire-reports from your project's root directory.
Related information
AWS CloudFormation CLI (from the GitHub website)