Sls invoke local giving error

I am trying to invoke a lambda locally using the following command
sls invoke local -f function
but I am getting the following error
Error: Artifact undefined doesn’t exists, please compile it first.
at /usr/local/lib/node_modules/serverless/lib/plugins/aws/invokeLocal/index.js:646:21

I have created the lambda in java and i also tried building the package using maven but still facing the error
Any idea how to resolve this?