java.lang.ClassNotFoundException: helloworld.App

See original GitHub issue

Simplest hello world example fails. Didn’t change anything after sam init See below:

$ pip install --user aws-sam-cli
$ sam init --runtime java8
$ cd sam-app
$ mvn compile package
$ sam local start-api
2018-07-23 17:59:27 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]
2018-07-23 17:59:27 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template
2018-07-23 17:59:27  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)
2018-07-23 17:59:33 Invoking helloworld.App::handleRequest (java8)
2018-07-23 17:59:33 Found credentials in shared credentials file: ~/.aws/credentials
2018-07-23 17:59:33 Decompressing /home/eugenevd/dev/advance/projects/aws/sam-test-java/sam-test-java/target/HelloWorld-1.0.jar

Fetching lambci/lambda:java8 Docker container image......
2018-07-23 17:59:37 Mounting /tmp/tmpAUnDiP as /var/task:ro inside runtime container
START RequestId: 82172e78-ce88-447a-8893-88a6cb0e2389 Version: $LATEST
java.lang.ClassNotFoundException: helloworld.App
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)

END RequestId: 82172e78-ce88-447a-8893-88a6cb0e2389
REPORT RequestId: 82172e78-ce88-447a-8893-88a6cb0e2389  Duration: 2.82 ms       Billed Duration: 100 ms Memory Size: 128 MB    Max Memory Used: 3 MB
2018-07-23 17:59:38 Function returned an invalid response (must include one of: body, headers or statusCode in the response object). Response received:
2018-07-23 17:59:38 127.0.0.1 - - [23/Jul/2018 17:59:38] "GET /hello HTTP/1.1" 502 -
2018-07-23 17:59:38 127.0.0.1 - - [23/Jul/2018 17:59:38] "GET /favicon.ico HTTP/1.1" 403 -

I checked the code, the package, the classname, function name, and template.yaml All appears correct. .jar file contents also look correct to me:

$ jar -tvf target/HelloWorld-1.0.jar
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/
   134 Mon Jul 23 18:05:18 SAST 2018 META-INF/MANIFEST.MF
     0 Mon Jul 23 18:05:18 SAST 2018 helloworld/
  2699 Mon Jul 23 18:05:18 SAST 2018 helloworld/App.class
  1216 Mon Jul 23 18:05:18 SAST 2018 helloworld/GatewayResponse.class
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/helloworld/
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/helloworld/HelloWorld/
  1509 Mon Jul 23 18:05:04 SAST 2018 META-INF/maven/helloworld/HelloWorld/pom.xml
   104 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/helloworld/HelloWorld/pom.properties
     0 Mon Jul 23 18:05:18 SAST 2018 com/
     0 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/
     0 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/
     0 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/
     0 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/
   288 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/Client.class
   367 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/ClientContext.class
   224 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/CognitoIdentity.class
   636 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/Context.class
   181 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/LambdaLogger.class
   761 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/LambdaRuntime$1.class
   688 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/LambdaRuntime.class
   580 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/LambdaRuntimeInternal.class
   408 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/RequestHandler.class
   327 Mon Jul 23 18:05:18 SAST 2018 com/amazonaws/services/lambda/runtime/RequestStreamHandler.class
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/com.amazonaws/
     0 Mon Jul 23 18:05:18 SAST 2018 META-INF/maven/com.amazonaws/aws-lambda-java-core/
  3892 Wed Oct 07 16:34:36 SAST 2015 META-INF/maven/com.amazonaws/aws-lambda-java-core/pom.xml
   118 Wed Oct 07 16:43:16 SAST 2015 META-INF/maven/com.amazonaws/aws-lambda-java-core/pom.properties

Advice?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

20reactions
florentcuretcommented, Mar 20, 2019

@eugenevd, I had the same error until I ran sam build before running sam local start-api

3reactions
richogreencommented, Aug 14, 2018

I had the same issue.

Resolved by running maven clean package prior to running sam local start-api.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.ClassNotFoundException: helloworld.App #571
Simplest hello world example fails. Didn't change anything after sam init See below: $ pip install --user aws-sam-cli $ sam init --runtime ...
Read more >
Java.lang.classnotfoundexception - HelloWorld.class
I have set the CLASSPATH in Environment Variables to C:\Program Files\Java\jdk-10.0.2\bin . I can compile the code into a .class file using ...
Read more >
java.lang.ClassNotFoundException: helloworld.App
Simplest hello world example fails. Didn't change anything after sam init. See below: $ pip install --user aws-sam-cli $ sam init --runtime ...
Read more >
How to resolve java.lang.ClassNotFoundException in Java ...
1) First find out the jar file on which problematic class file is present for example in case of "com. · 2) Check...
Read more >
Simple HelloWorld java program
Error: Could not find or load main class HelloWorldApp.class. Caused by: java.lang.ClassNotFoundException: HelloWorldApp.class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found