theawesomenayak / daily-news-java

A serverless API using AWS SAM
https://towardsdatascience.com/how-to-build-a-serverless-application-using-aws-sam-b4d595fe689f
3 stars 2 forks source link

Class not found: helloworld.App #1

Open luazhizhan opened 3 years ago

luazhizhan commented 3 years ago

Hi, I tried to deploy this application to my AWS cloud. I encountered this error when I call the hello API.

{
  "errorMessage": "Class not found: helloworld.App",
  "errorType": "java.lang.ClassNotFoundException"
}
Class not found: helloworld.App: java.lang.ClassNotFoundException
java.lang.ClassNotFoundException: helloworld.App
    at java.base/java.net.URLClassLoader.findClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Unknown Source)
luazhizhan commented 3 years ago

I have found the solution. The CodeUri attribute in AWS::Serverless::Function resource written in template.yaml only works locally. It will require a different value for it to work on the AWS cloud.

For local build, use the API folder name.

CodeUri: HelloWorldFunction

For deployment build, it has to be the path to the jar file that is built by running this command, mvn clean package. Which in this case is

CodeUri: ./HelloWorldFunction/target/HelloWorld-1.0.jar