AWS|Packaging|Artifact|Java : ClassNotFoundException

Hi

This might not be a direct serverless issue, but it is related to packaging of dependencies, along with the handler code, into a zip, which is then specified in serverless.yaml as [ package:artifact:package.zip ]

According to these instructions by AWS, they prescribe that one should put your own code at the root of the zip, and dependency jars inside a lib/ directory. Eg:

ZIP
my/code/Handler.class
lib/dependency.jar

The Handler class implements RequestHandler<Map<String, Object>, String> with a a method public String handleRequest(Map<String, Object> event, Context context) as per Lambda Function Handler (java) :docs.aws.amazon.com /en_en/ lambda/latest/dg/java-programming-model-handler-types.html

I’ve tried both handler definitions:
functions:hello:handler: my.code.Handler
functions:hello:handler: my.code.Handler::handleRequest

I’ve tried deployment via serverless, and via ‘cloudformation package/deploy’ all resulting in ClassNotFoundExceptions.

Any suggestion or ideas would be welcomed.

Thanks
Eugene

PS. To try this problem from another angle, but still the same core problem: I found another project on github where this type of packaging was mentioned. I retrofitted one of their samples with maven directives and recreated the problem. If that might help to show the problem, see https://github.com/awslabs/aws-serverless-java-container/issues/133#issuecomment-400712212

A classpath is a list of locations to load classes from. These ‘locations’ can either be directories, or jar files. The JVM will attempt to look in the directory classes first, then in .Jar files. When you get a ClassNotFoundException, it means the JVM has traversed the entire classpath and not found the class you’ve attempted to reference. This may be something that can happen in the distribution or production of JAR files, where not all the required class files were included.

Thanks for the good ideas to bring it. I know a lot more. :slight_smile: [url=[http://balltoyou.com][size=1px]ดูบอล[/size]/url] :J