sam invoke not working for java8. Getting class not found exception!
I am getting Class not found exception while running sam invoke.
I ran below commands.
sam init --runtime java8
cd sam-app
sam build
sam local invoke "HelloWorldFunction" -e test.json
I got below error.

I am using window 7 OS. Please let me know if I am missing something.
Thanks in advance!
See #1436. This is a docker problem.
Thanks.
Hi - this appears to still be an issue on Mac, and I've got my project (or a parent) shared as a volume via Docker Desktop. I can even see my folder being mounted in the log:
❯ sam local invoke -t template.yaml -e events/event.json
Invoking HelloWorld.Handler::handleRequest (java11)
libs is a local Layer in the template
Building image........................
Skip pulling image and use local one: samcli/lambda:java11-arm64-739a304e183a900711f6497e6.
Mounting /Users/localuser/repos/project/HelloWorld/HelloWorldFunction as /var/task:ro,delegated inside runtime container
START RequestId: 0f43f7f4-38c8-49ec-9b9d-03e14bfdee4e Version: $LATEST
Class not found: HelloWorld.Handler: java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: HelloWorld.Handler. Current classpath: file:/var/task/
END RequestId: 0f43f7f4-38c8-49ec-9b9d-03e14bfdee4e
REPORT RequestId: 0f43f7f4-38c8-49ec-9b9d-03e14bfdee4e Init Duration: 0.21 ms Duration: 238.76 ms Billed Duration: 239 ms Memory Size: 512 MB Max Memory Used: 512 MB
{"errorMessage":"Class not found: HelloWorld.Handler","errorType":"java.lang.ClassNotFoundException"}%
My project layout:
❯ tree
.
├── README.md
├── events
│ └── event.json
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── layers
│ └── build.gradle
├── out.json
├── HelloWorldFunction
│ ├── build.gradle
│ └── src
│ ├── main
│ │ └── java
│ │ └── HelloWorld
│ │ └── Handler.java
├── samconfig.toml
├── settings.gradle
└── template.yaml
16 directories, 22 files
Huh - looks like removing the -t template.yaml argument changed the error and it looks like it's running okay (or at least failing elsewhere).
Had this problem with maven and only when running remotely on AWS and thanks to https://youtu.be/Q14uFOshVa8?t=165 all it took to work was to run mvn clean package before sam build and change the CodeUri of the sam template to
CodeUri: HelloWorldFunction/target/HelloWorld-1.0.jar
Still, does not fill right that we have to do this extra steps that could be done by generic sam cli calls.